Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
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 15.6.85.37198 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

<system.web>
    <compilation targetFramework="4.7.2" debug="true">
      <assemblies>
        <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
      </assemblies>
    </compilation>
    <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 15.6.85.37198. 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.

Questions
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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...