2
votes

It may seem like forever ago but I still have a requirement to develop a class library which targets .NET Framework 2.0. Our build scripts require Visual Studio 2010 and invoke devenv.exe, passing it the path to our solution file.

We have a new requirement to produce a class library which targets .NET Core 2.0 (with a long-term goal of targeting a .NET Standard version). With the redesign of .NET, we no longer need an IDE and instead require the .NET Core 2 SDK tooling.

I noticed that the dotnet build command accepts a --framework argument. The Target Frameworks page shows net20 a supported TFM. As a let's see what happens effort, I targeted net20 and was met with the following error message:

C:\cli\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v2.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\path\to\my\project.csproj]

Within the Application tab of my project's properties in Visual Studio 2017, the Target Framework dropdown has a Install other frameworks... link. The oldest .NET Framework version listed is 3.5 SP1 and has no Dev Pack reference. Is what I'm trying to do possible? If so, where can I find the .NET Framework 2.0 Targeting Pack?

2

2 Answers

1
votes

The .NET CLI (dotnet build and similar commands) cannot be used when targeting .NET versions lower than 4.* because MSBuild works differently for these frameworks and the .NET Core version of MSBuild cannot perform the required actions. However, you can use msbuild.exe from the developer command prompt.

In order to build for the 2.* CLR, you need to have the framework installed. The targeting packs are a 4.* concept and msbuild expects to be able to use the installed framework for applications targeting .NET < 4.*. (to be specific: MSBuildTaskHost.exe will be run using the .NET 3.5 framework).

While I have not tried to build for 2.0, building for 3.5 (which is the only version still supported by microsoft (3.5 SP1)) is possible and supported.

0
votes

Actually it is not that hard to find .NET 2.0 despite the fact that Microsoft does not like to make it easy

(i) .NET Framework 2.0 Software Development Kit (SDK) (x64) or

(ii) .NET Framework 2.0 Software Development Kit (SDK) (x86)

Another problem is to get .NET Core build system using .NET Framework 2.0 as a target. Roslyn supports targeting .NET 2.0 but it is hard to tell how .NET Core build system will behave. However, since everything is open source it surely can be done. The only question is how much work it would require. Try using frameworks I have indicated and post the results, perhaps, I could help to move past some problems.