1

I need to create a very simple WinForms C# application that only requires .NET Framework 2.0 to execute properly (due to the fact that the customer isn't allowed to upgrade or connect his computer to the Internet).

On my computer I have Visual Studio (VS) 2005 and VS2019 installed.

  1. I first tried VS2005 and created an empty WinForms application and sprinkled the project file with <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> tags and compiled.
  2. I then checked the .exe-file inside JetBrains dotPeek (according to a tip I found on How to find out which version of the .NET Framework an executable needs to run?) but it says it's .NET 3.5 application.
  3. I then tried with VS2019, but I didn't have to manipulate the project file manually, instead I used the user-friendly dropdown for selecting target framework and set it to 2.0. However, the result was the same, the application became a .NET 3.5 application.

Does anybody know what I'm doing wrong?

Julius A
  • 38,062
  • 26
  • 74
  • 96
arnold_w
  • 59
  • 9
  • 1
    Do you have .NET Framework 2.0 installed on your local machine? Here is the link, https://www.microsoft.com/en-gb/download/details.aspx?id=6523 – Julius A May 04 '21 at 11:35
  • Have you considered MSBuild.Sdk.Extras? Here's protobuf-net (the old v2 branch) which builds using a SDK-style csproj, but targets (among other things) .NET Framework 2.0 - https://github.com/protobuf-net/protobuf-net/blob/2.4.1/src/protobuf-net/protobuf-net.csproj - the important lines are `` and `net20`; here's the MSBuildSdkExtras project page, with more info: https://github.com/novotnyllc/MSBuildSdkExtras – Marc Gravell May 04 '21 at 11:38
  • Also you can check which .NET Frameworks installed using instructions from https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed – Julius A May 04 '21 at 11:45
  • In solution explorer check the reference. You may need to delete some references. – jdweng May 04 '21 at 11:55
  • 1
    Julius A: I downloaded this tool https://github.com/jmalarcon/DotNetVersions and this is the output: ```Currently installed "classic" .NET Versions in the system:``` ```2.0.50727.4927 Service Pack 2``` ```3.0.30729.4926 Service Pack 2``` ```3.5.30729.4926 Service Pack 1``` ```4.0.0.0``` ```4.8.04084``` – arnold_w May 04 '21 at 11:59
  • jdweng: I have the following references: Analyzers, System, System.Data, System.Drawing and System.Windows.Forms. When I look at the properties, they all (except Analyzers) have paths to C:\Windows\Microsoft.NET\Framework\v2.0.50727... – arnold_w May 04 '21 at 12:12
  • Marc Gravell I'm unable to install Nuget package MSBuild.Sdk.Extras: "Package 'MSBuild.Sdk.Extras 3.0.23' has a package type 'MSBuildSdk' that is not supported by project 'MyProject'". – arnold_w May 05 '21 at 08:55
  • The "funny" thing is that even if I compile using C:\Windows\Microsoft.NET\Framework\v2.0.50727\MsBuild.exe "MyProject.csproj" /t:build /p:configuration=Debug /verbosity:quiet then my application still becomes a .NET 3.5 application. Do I need to install Window 98 and compile on that computer in order to avoid getting .NET 3.5? – arnold_w May 05 '21 at 09:03

1 Answers1

0

The problem appears to be that JetBrains dotPeek is not reliable. I tried an .exe-file that JetBrains dotPeek reported was using .NET Framework 3.5, but I had no problems executing it on computer with only Windows 2000 and .NET Framework 2.0 installed. I agree with this answer How to find out which version of the .NET Framework an executable needs to run? that it's better to inspect the .exe-file in Notepad to determine which .NET version it requires.

arnold_w
  • 59
  • 9