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?
json file is generated in the process of restoring the NuGet packages in projects that use project. json . It holds a snapshot of all the information that is generated as NuGet walks the graph of packages and includes the version, contents, and dependencies of all the packages in your project.
To resolve the error, remove the % from the folder name, and rerun dotnet build . A change to the project file wasn't automatically detected and restored by the project system. To resolve the error, open a command prompt and run dotnet restore on the project.
json' doesn't have a target for 'netcoreapp3. 1'. If you restore your project using an older version of nuget.exe, msbuild, dotnet, or Visual Studio and then build your project using a newer version of msbuild, dotnet, or Visual Studio, you can run into the error NETSDK1005.
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.
Restarting Visual Studio solved the error for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With