error NETSDK1004 after porting to new csproj format

We were using TeamCity and VS2015 build tools to build projects targeting .NET 4.5 with a "Visual Studio (sln)" build step in the past with no issues.

Our development machines use VS2017, and I recently ported all projects to .NET 4.7.2 and converted them to the new csproj format looking like this:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Visual Studio build properly and everything's fine, but under TeamCity I got "error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found."

So on the TeamCity machine I installed the VS2019 build tools (skipping 2017, why not?). I installed the tools for everything, including .Net Core even if our project is not targeting it.

I then had the error "Version 2.2.202 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.6.85.37198.".

I'm not sure why it try to build using .NET Core, but I guess it's the result of this new csproj format and that it is not an issue?

TeamCity would only use MSBuild 15 because it had "Visual Studio 2017" in the build steps. In order to select "Visual Studio 2019" and have MSBuild 16, I had to upgrade TeamCity to build 2019.1 EAP3, which I did successfully.

Now, when I build I get this error:

C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208, 5): error NETSDK1004: Assets file 'C:\TeamCity\buildAgent\work\d736425a249d5121\Sources\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

When I look locally on a dev machine at the obj directory, I do have this project.assets.json file being generated by Visual Studio on build.

 

Now I found this thread which the last comment have a similar problem:

https://teamcity-support.jetbrains.com/hc/en-us/community/posts/115000104510-Visual-Studio-2017-sln-Runner

So I tried to update NuGet.exe (under Administration -> Tools). I installed NuGet 5.0.0 and uninstalled all previous version (was previously using 3.2). Unfortunately, it did not resolve anything, I still get the same error.

So what am I missing?

 

 

Another question, is the Visual Studio (sln) build step the proper one to use in my situation (which is a simple c# project)? Should I transform my build step to use .NET CLI (dotnet) build or MSBuild instead?

 

Thanks

0
1 comment
Avatar
Permanently deleted user

I finally managed to build successfully by selecting the NuGet Installer step and switching Restore mode to "Restore" instead of "Install" under the advanced settings.

0

Please sign in to leave a comment.