How do I get a .net standard 2.0 project to build on TFS2015

Viewed 3879

I have a .net standard 2.0 class library in a .net 4.7.1 web solution.

Building the solution locally works fine, but when the TFS server builds the solution it is unable to compile the .net 2.0 standard library. It crashes during compilation and complains that system.object etc is not defined or imported.

It's a TFS 2015 running the old tfsbuild.proj style xml files. The build server is otherwise up to date with .net 4.7.1, latest .net core 2.0.3, latest visual studio, latest build tools.

I can see that it generates a csc.exe command to compile the .net standard 2.0 project that crashes. If I simply was to run "dotnet build", it works great.

Watching the logs of the build I can see that the CoreCompile step when running in VS or "dotnet build" contains a "References" Task Parameter with references to the .net standard 2 library. This Task Parameter is missing in the CoreCompile step when the build server is running the build.

Does anyone have a suggestion on how to best proceed to get msbuild on the tfs server to successfully compile the .net standard 2.0 project?

Could I get msbuild to generate the necessary "References" task parameter?

Is my best option to turn off automatic building of .net standard projects and try to do everything manually as build steps with "dotnet build" instead, since dotnet build correctly identifies the necessary references?

2 Answers

Seems you are trying to use the VS2015 MSBuild tools to build a solution which includes a .NET Standard 2.0 project.

The .NET team changed the project file structure (first announced here) for new .NET Core and .NET Standard projects along with the release of Visual Studio 2017.

Support for building .NET Core/Standard came with the TFS 2017 Update 2 update.

.NET Core tasks support project files

With the current update, we are enhancing .NET core tasks to support *.csproj files in addition to project.json. You can now use Visual Studio 2017 on your build agents to build .NET core applications using csproj files.

As a workaround, you could try to give up of using the TFS 2015 build task MSBUILD and Visual Studio Build, and now use the Command Line step. In general, if you can perform a task on the commandline you can also do it in TFS/VSTS. More detail steps please refer this blog: Building .NET Core and .NET Standard Projects in TFS 2015

Related