如何将这段C#代码编译成DLL?

发布于 2024-12-11 01:49:58 字数 1180 浏览 0 评论 0 原文

在我正在运行的项目中,我需要将此代码编译成 DLL:

// svgzHandler.cs 
using System; 
using System.Web;
namespace svgzHandler
{
    public class svgzHandler : IHttpHandler
    {
        #region IHttpHandler メンバー
        public bool IsReusable { get { return true; } }
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse r = context.Response;
            r.ContentType = "image/svg+xml";
            r.AppendHeader("Content-Encoding", "gzip");
            r.WriteFile(context.Request.PhysicalPath);
        }
        #endregion
    }
}

只是我不是程序员,不知道这一切意味着什么。另外,日文字符应该用什么替换?它是一个文件夹吗?一个文件?

我有 Visual Studio 2010 Ultimate,所以我有编译器,但这是我接触过的第一段 C# 代码。

感谢您的帮助!

PS:我不知道这是否有帮助,但这是带有说明的网站(翻译自日语):http://www.microsofttranslator.com/bv.aspx?ref=Internal&from=&to=en&a=http:// blog.wonderrabbitproject.net/post/2009/06/13/svgze381aee3838fe383b3e38388e383a9e38292IIS75e381a6.aspx

In a project I am running I need to compile this code into a DLL:

// svgzHandler.cs 
using System; 
using System.Web;
namespace svgzHandler
{
    public class svgzHandler : IHttpHandler
    {
        #region IHttpHandler メンバー
        public bool IsReusable { get { return true; } }
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse r = context.Response;
            r.ContentType = "image/svg+xml";
            r.AppendHeader("Content-Encoding", "gzip");
            r.WriteFile(context.Request.PhysicalPath);
        }
        #endregion
    }
}

Only I am no programmer and have NO IDEA WHAT THIS ALL MEANS. Also, what should the japanese characters be replaced by? is it a folder? a file?

I have Visual Studio 2010 Ultimate so I do have the compiler but This is the first bit of C# code i've ever touched.

thank you for your help!

P.S: I don't know if this will help but this is the site with the instructions (translated from japanese): http://www.microsofttranslator.com/bv.aspx?ref=Internal&from=&to=en&a=http://blog.wonderrabbitproject.net/post/2009/06/13/svgze381aee3838fe383b3e38388e383a9e38292IIS75e381a6.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜`诱少女 2024-12-18 01:49:58

日语字符位于节名称内,编译器会忽略该节名称。如果 #region#endregion 令您烦恼,您可以完全删除它们。组织代码是 Visual Studio 的事情,编译器不使用它们。因此,要编译为程序集,只需在 Visual Studio 中创建一个类库类型的新项目并将此类添加到其中即可。您必须引用 System.Web 程序集才能成功编译为 IHttpHandler 在此代码中使用的接口是在那里定义的。

因此,实际代码可能很简单(svgzHandler.cs):

namespace svgzHandler 
{
    using System; 
    using System.Web; 

    public class svgzHandler : IHttpHandler
    {
        public bool IsReusable { get { return true; } }

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse r = context.Response;
            r.ContentType = "image/svg+xml";
            r.AppendHeader("Content-Encoding", "gzip");
            r.WriteFile(context.Request.PhysicalPath);
        }
    } 
}

顺便说一句,您甚至不需要 Visual Studio 来进行编译。您可以直接使用 C# 编译器

c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:library svgzHandler.cs

它会生成 svgzHandler.dll汇编。

The Japanese characters are inside a section name which is ignored by the compiler. You could completely get rid of the lines #region and #endregion if they bother you. It's a Visual Studio thing to organize code, the compiler doesn't use them. So to compile to an assembly, simply create a new project in visual studio of type Class Library and add this class to it. You will have to reference the System.Web assembly in order to successfully compile as the IHttpHandler interface that is used in this code is defined there.

So the actual code could be simply (svgzHandler.cs):

namespace svgzHandler 
{
    using System; 
    using System.Web; 

    public class svgzHandler : IHttpHandler
    {
        public bool IsReusable { get { return true; } }

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse r = context.Response;
            r.ContentType = "image/svg+xml";
            r.AppendHeader("Content-Encoding", "gzip");
            r.WriteFile(context.Request.PhysicalPath);
        }
    } 
}

And by the way you don't even need Visual Studio in order to compile. You could directly use a C# compiler:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:library svgzHandler.cs

which would spit a svgzHandler.dll assembly.

冷清清 2024-12-18 01:49:58
  1. 创建一个新的类库项目(文件 -> 新项目 -> 类库)
  2. 添加对 System.Web 的引用(右键单击解决方案资源管理器中的“引用”,转到 .NET 选项卡,选择 System.Web)
  3. 替换代码在默认的 class1.cs 文件中,您的代码在那里,只需剪切和粘贴,不用担心外来字符,它们只是在编译器不关心
  4. 构建的区域语句中(选择构建菜单选项,然后构建解决方案)

你的dll将在项目的 bin/debug 目录

  1. Create a new Class Library project (File -> New Project -> Class Library)
  2. Add a reference to System.Web (right click "References" in solution explorere, go to .NET tab, select System.Web)
  3. Replace the code in the default class1.cs file with your code there, just cut and paste and don't worry about the foreign characters, they're just in a region statement that the compiler doesn't care about
  4. Build (select build menu option then build solution)

Your dll will be in the bin/debug directory of the project

把人绕傻吧 2024-12-18 01:49:58

创建一个类库项目,将代码放在那里,修复命名空间,构建,然后瞧!

Create a Class Library project, put the code there, fix namespaces, build and voilá!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文