Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

visual studio - How to compile Full .NET along with NETStandard project

I have Full .NET 4.7.2 Web API project. This is existing project. On CI server I am building this project using MSBuild version from C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binmsbuild folder

I added another NETStandard2 library project that has common code. The Web API 2 project now has a project reference to this NETStandard2 project.

Also updated The Web Api's config as

    <compilation targetFramework="4.7.2" debug="true">
        <add assembly="netstandard, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
    <httpRuntime targetFramework="4.7.2" />

On local machine I am using VS 2019 and both projects are compiling.

On CI server I have installed new NET 5 SDK. I am building Web Project as

C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binmsbuild MyApi.csproj /p:Configuration=Release

Its throwing error

error : Version 5.0.101 of the .NET Core SDK requires at least version 16.8.0 of MSBuild. The current available version of MSBuild is Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.

The error is self explanatory. Since web api is referencing NetStandard I have to install MSbuild 16*

However, from MS documentation

To install MSBuild on a system that doesn't have Visual Studio, go to Visual Studio downloads and scroll down to All Downloads, then expand Tools for Visual Studio 2019. Install Build Tools for Visual Studio 2019, which includes MSBuild, or install the .NET Core SDK.

the last part says or install the .NET Core SDK.

1> I have installed NET5 SDK on CI server, Does that also installs MSbuild 16.*, if yes which location?
2> Where is global.json file located?

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should note that .NET5 is only available for at least VS2019 16.8 and it cannot work with VS2017 and MSBuild 15.x. See the Visual Studio support of Net5.0.

NET 5.0 is dontet cli tool while MSBuild 16.x is build tool for VS, they are two different tools that do not interfere with each other.

To use it, you should download Build Tool for VS2019 and remember to check the Net Core build tool workload, .Net Desktop Build tool workload and any other build workloads you used.

Or you have to check this document to use a lower Net Core SDK which supports msbuild 15.6(like Net Core 2.1.201).

Note: change global.json file is not a good choice and it changes your internal project and it is at risk. Obviously, changing external build tools is more secure and compliant.

Update 1

Install VS2019 IDE on the Build server which solves the issue.

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share