Compile DLL .NET2.0 from .NET4.0
I am using .NET4.0, but for compatibility reasons, I would like to compile the .NET2.0 dll from C #. There should be no .NET4.0 accessibility used in the script, so it should work fine in a .NET2.0 environment. Is there any command line syntax in csc that I can specify the version number from?
source to share
You mentioned csc.exe
, so I am assuming that you will not be building with Visual Studio, but rather from the command line. Also, I am assuming msbuild
not available on the build machine.
I believe that csc.exe
applies to each version. For example, in the folder C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
you will find csc.exe
, and in the folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
you will find a different version csc.exe
.
To create .NET 2.0 dll, you have to link to csc.exe
from v2.0 ( C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
) folder .
Hooray!
source to share
If you build with MSBuild (which of course includes from VS), you can specify the target environment version from the project properties dialog. However, if you are creating by hand, there seems to be no surefire way to express this limitation .
source to share
Set the target framework to 2.0 in the project properties. If you are using features like LINQ that are not in Framework 2.0, this approach will not work. If you want full compatibility with a 2.0 framework, you must write your code for 2.0 and then compile targeting 4.0 later if you need to.
source to share