0

I have a SDK styled .Net class library which compiles properly on my local machine, however fails on build server.

The contents of .csproj are

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net35;net40;netstandard1.0</TargetFrameworks>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <Version>1.5.6</Version>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>

</Project>

The error displayed is: NETSDK1045: The current .NET SDK does not support targeting .NET Standard 4.0. Either target .NET Standard 2.1 or lower, or use a version of the .NET SDK that supports .NET Standard 4.0

I have .NET Core 3.1.113 installed on build server and .NET 5 installed on local machine.

Note: If I remove netstandard1.0 from TargetFrameworks then build succeeds on both the machines. However I want my library to target .net standard 1.0 as well.

I cannot understand why v4.0 is treated as .NET Standard 4.0 on build server. Can anyone let me know what the problem might be?

Durga Prasad
  • 939
  • 10
  • 20
  • How did you build your project on build machine? Dotnet build or any other? Could you please share the build command line with us? – Sara Liu - MSFT Apr 23 '21 at 02:39
  • I am using msbuild that gets shipped with visual studio 2019 and passing in the project name as parameter. The msbuild tool is located at : C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin – Durga Prasad Apr 23 '21 at 06:39
  • Sure. If that situation, you should check your VS 2019 in the vs installer, modify it, and check if you install all the sdks on that. – Sara Liu - MSFT Apr 23 '21 at 06:46
  • If I remove the attribute, then it is working. However, I cannot remove it because my build server is configured in a way that it always looks for in csproj file. Any idea what the value will be for if target frameworks are 3 as listed in question?Also the purpose of it? – Durga Prasad Apr 23 '21 at 10:01

2 Answers2

2

Remove the following line from your .csproj file:

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

This overrides the version value that the SDK infers from TargetFramework which will interfere with your definition of net3.5 and so on - you were actually building .NET Framework 4.0 twice and then override netstandard1.0 to .NET Standard (inferred TargetFrameworkIdentifier) to 4.0. Newer versions of the SDK may have different inference logic which may be a difference between 3.1 and 5.0 SDKs but this is an error in the csproj nonetheless.

If your build logic relies on TargetFrameworkVersion being defined in the project I suggest you try to change your build logic - this is VERY DANGEROUS to have in a modern csproj file where you rely on TargetFramework and TargetFrameworks (plural). You can also try to move it into a separate <PropertyGroup> with an always-fals-condition (e.g. <PropertyGroup Condition="'$(ThisIsToWorkAroundBuildScripts)' == 'True'">)

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • 1
    Thank you, this answer provided lot of insight into what I was trying to understand. Rather than moving TargetFrameworkVersion into an always false condition, I used the following: v4.0 v3.5 v1.0 – Durga Prasad Apr 25 '21 at 15:59
-1

I cannot understand why v4.0 is treated as .NET Standard 4.0 on build server. Can anyone let me know what the problem might be?

That is quite strange and I have not seen that issue before. And there is no info about .NET Standard 4.0 and I did not know why VS treats v4.0(net framework 4.0) as net standard 4.0. Maybe your there is some problems about your server environment.

Please follow these:

1) First, please use dotnet --list-sdks under CMD to check if you installed net core 2.1 sdk or any other versions. And actually, net core 2.1 sdk could support the previous sdks including net standard 1.0. Maybe you would better install net core 2.1 sdk. Also, you could install the latest Net Core 3.1 Sdk.

2) check system environment variable, and find whether there is a variable called MSBuildSDKsPath, if so, please delete it. Then, restart.

3) delete bin and obj folder under the build server. Also, I suggest you would better use Build Tool for VS to build your projects on the server rather than dotnet build. dotnet cli does not contain the tool for net framework. What's more, your project is multi-targetframeworks, it could build net core and net standard, and also you have to download net framework sdk.

That is too complex, you could install the Build Tool for VS2019(more likely a lightweight cmd which integrates dotnet, net framework, all vs environment). Also, install the Net desktop build tool and net core build tool workload, also install the related sdks.

enter image description here

When you finish it, delete bin and obj folder, type this under Build Tool for VS command:

msbuild xxx\xxx.csproj -t:clean,restore,build 
Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27