3
votes

We're creating a new Windows application with a WPF interface. For various reasons, we are attempting to make all of the supporting libraries run on net standard 2.0.

So the WPF project, Foo, references .NET Standard 2.0 projects from the same solution.

My problem is with getting the solution to build on the TeamCity build server.

msbuild gives an error when building the solution (works fine in Visual Studio 2017).

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error, 'Cannot resolve dependency to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' [Src\Foo\Foo.csproj]

If I use nuget to add NetStandard.Library to the Foo project, then I get a different error from msbuild (still works fine in visual studio).

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore. [Src\Foo\Foo.csproj]

There isn't a projects.json file.

It's running with 15.0 version of msbuild

External Program Failed: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MsBuild.exe (return code was 1)

2

2 Answers

0
votes

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error, 'Cannot resolve dependency to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' [Src\Foo\Foo.csproj]

The error message indicates you are using MSBuild for .NET Framework 4.0 to attempt to compile your assembly.

You should use dotnet msbuild to compile your .NET Standard 2.0 library and do note you need to have the .NET Core 2.0 SDK installed on the build machine.

dotnet msbuild /p:Configuration=Release

A simple way to install the .NET Core 2.0 SDK remotely on a CI server is to execute the dotnet-install script.

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore. [Src\Foo\Foo.csproj]

This error indicates your build server has a preview version of the .NET Core SDK on your server that uses project.json format. You will need the .NET Core 2.0 SDK in order to build.

0
votes

Starting with a fresh build server solved the problem. I guess there were too many versions of msbuild and visual studio or SDKs or something on the old ones.