Assets file obj\project.assets.json doesn't have a target - VS2017

Paolo B picture Paolo B · Mar 20, 2018 · Viewed 30.7k times · Source

Using Visual Studio 2017, AspNetCore 1.1.2

All of a sudden I am getting following error when I am trying to publish (Release build) any project in the solution:

Assets file 'C:\example\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v4.5.2/win7-x86'. Ensure that restore has run and that you have included 'net452' in the TargetFrameworks for your project. You may also need to include 'win7-x86' in your project's RuntimeIdentifiers.

Have checked in the project.assets.json files, I have:

"targets": {
  ".NETFramework,Version=v4.5.2": {

and

"runtimes": {
  "win7-x86": {
    "#import": []
  }

In the *.csproj files I have:

  <PropertyGroup>
      <TargetFramework>net452</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
      <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup> 

Have made no changes to config in the projects. Only thing is that I have updated VS2017 to latest version today, 15.6.3. Could this cause issue?

Answer

Mike Gledhill picture Mike Gledhill · Oct 1, 2018

According to the Microsoft blog (which, bizarrely, my account doesn't have permissions to post in), this isn't a bug, and is entirely caused by ReSharper. If you disable this, the problem goes away.

Errr, one problem: I'm getting this error, and I don't have ReSharper.

After a lot of hunting around, I found the reason I was getting the error on my .Net Core project which had been upgraded from 1.0 to 2.1.

When running my project in Debug or Release mode, everything worked fine, but when I tried to publish to Azure, I got that error:

Assets file '(mikesproject)\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project.

Although I had updated the version of .Net Core to 2.1 in Project\Properties and upgraded the various nuget packages, there was one place which hadn't picked up this change... the Publish Profile file.

I needed to go into the Properties\PublishProfiles folder in my solution, open up the .pubxml file relating to the way I was publishing to Azure, and change this setting from netcoreapp2.0 to netcoreapp2.1:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    . . . 
    <TargetFramework>netcoreapp2.0</TargetFramework>
    . . . 
  </PropertyGroup>
</Project>

Ridiculous, hey ?

I do wish Microsoft error messages gave some clue as to the source of problems like this.