简体   繁体   中英

How to build a single .cs file inside the project and get the DLL for that file?

Is it possible to get the DLL file for a single .CS file inside a big project ?

For eg: I have a project named 'Operations' in VS2012 where I have numerous window forms and .CS files.

I need to get a DLL file for the .CS files (which I have changed)... I know we can build the entire project and get the DLL file but how do I get the DLL file for one specific .CS file in that Project ?

Thanks

我认为最简单的方法是将文件移到其自己的项目中,并在需要访问类时引用该项目。

A DLL is the output for a library project, and not for a cs file.

If you want to have a dll for the specific class, - create a new project with the specific .cs - compile it in a new dll file - add the reference to the new dll file in your main porject

It is possible as long as you have no dependencies on the other files in your project.

You can see different options How to: Build a Single-File Assembly

In short to create a single file dll you can use one of these command lines

:: will create File.dll
csc File.cs -t:library
:: will create FileOther.dll
csc File.cs -t:library -out:FileOther.dll

One of these to create a single file exe (file must have static main somewhere for an entry point)

:: will create File.exe
csc File.cs 
:: will create FileOther.exe
csc -out:FileOther.exe File.cs

To create a dll or exe from multiple files you can specify multiple files on the command line: note that if doing an exe then either: only one should have a static main; OR you need to also use the /main switch

:: will create File.dll
csc File.cs File2.cs -t:library

:: will create File2.dll
csc File2.cs File.cs -t:library

:: will create File.exe
csc File.cs File2.cs
:: will create FileOther.exe
csc -out:FileOther.exe File.cs File2.cs

:: will create FileOther.exe using the entry point from NAMESPACE_WITH_MAIN_TO_USE
csc -out:FileOther.exe File.cs File2.cs /main:NAMESPACE_WITH_MAIN_TO_USE

:: will create alldirectory.exe
csc -out:alldirectory.exe *.cs

More general usage for the command line compiler can be found at Command-line build with csc.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM