dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.72k stars 1.07k forks source link

VS2017 publish: project.assets.json doesn't have a target for .NETCoreApp,Version=v1.1 #1321

Closed rainersigwald closed 6 years ago

rainersigwald commented 7 years ago

From @kosa-gyula-77 on June 8, 2017 14:27

Publishing the xunitCore1.0 project in the solution attached from Visual Studio 2017 fails with the following error:

Assets file 'C:\Users\xxx\Documents\Visual Studio 2017\Projects\xunitCore1.0\xunitCore1.0\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v1.1'. Ensure you have restored this project for TargetFramework='netcoreapp1.1' and RuntimeIdentifier=''.

Could you please help in identifying why I'm getting this error? xunitCore1.0 targets netcoreapp1.0.

xunitCore1.0.zip

Thanks.

Copied from original issue: Microsoft/msbuild#2196

asvishnyakov commented 6 years ago

See #2068 for info about problem with 2.1.102 SDK

scottfavre commented 6 years ago

I'm having this problem but do not have ReSharper enabled (it is installed but suspended).

hughbiquitous commented 6 years ago

@scottfavre I found that suspending wasn't enough; I had to disable it through Tools -> Extensions and Updates.

michelmoorlag commented 6 years ago

@hughbiquitous You are right, disabling ReSharper is the solution. I have an asp .netcore 2.0 project that used to publish fine. Today I only updated some minor string in my project. It builds and runs fine but when trying to publish it to azure I got:

"Assets file 'C:\xxx\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."

After googling for hours and only after disabling Resharper like hughbiquitous suggested I could finally publish again.

If I remember well I could publish in the past with ReSharper enabled and I did not update ReSharper that I know off. The only thing I did was updating Visual Studio to version 15.6.3.

zinov commented 6 years ago

This solution worked for me, is just adding an s in all to

https://stackoverflow.com/a/42855070/819153

how is this related to that?

Pilchie commented 6 years ago

This issue should be fixed in the 15.6.4 update that was published this morning.

Salgat commented 6 years ago

15.6.4 fixed it for me, thanks @Pilchie

cemilf commented 6 years ago

@Pilchie I can also confirm that 15.6.4 published the project without errors. It seems that the new dotenet sdk 2.1.103 installwd with the update solved the problem.

AndreyAkinshin commented 6 years ago

The problem is also fixed in ReSharper 2017.3.5, everything works with all combinations of Visual Studio and .NET Core SDK. You can find more technical details in the official blog post: https://blog.jetbrains.com/dotnet/2018/03/23/build-failures-visual-studio-15-6-3-resharper-ultimate-2017-3-5-rescue/

trandinhnam commented 6 years ago

Everything has been fixed on this version: vs15.6.4

----------MS ----------- Release Date: March 22, 2018 - Visual Studio 2017 version 15.6.4 Issues Fixed in this Release These are the customer-reported issues addressed in this release:

Assets File 'c:\xxxxxx\obj\project.assets.json' doesn't have a target for '.NETStandard,Version=v2.0'. VS2017 fails to persist settings on first launch if there is another VS instance running from another user. Android LLVM libc++ static library STL broken with VS15.6.0. Unit tests no longer sorted alphabetically. Test explorer tests grouped by class, namespace no longer sorted alphabetically in 15.6.2.

sergiobarriel commented 6 years ago

The solution from @dhieyson works for me!

martinprikryl commented 6 years ago

For me, recreating a .sln fixed the problem.

Darker commented 6 years ago

My solution was:

Change publish profile, this tag in particular:

<TargetFramework>netcoreapp2.0</TargetFramework>

From 1.0 to 2.0.

tunechr commented 6 years ago

For me, opening the 'Publish' Page, then open the 'Configure' dialog, then resaved. It probably just sorted the tags

nhustak commented 6 years ago

The solution from @tunechr fixed my issue.

mwpowellhtx commented 6 years ago

Hmm, well, I don't have a C:\Program Files\dotnet\sdk\2.1.102, so I don't know. Even after invoking the nuget.exe process with restore options, successfully I might add, the assets file lands where expected, I STILL get the error.

mwpowellhtx commented 6 years ago

Also, to be clear, I do use R#, but I do not have it enabled for build and run features.

mwpowellhtx commented 6 years ago

So... I wanted to follow up. I ended up pulling my C:\Program Files\dotnet\sdk folders aside, both 2.1.200 and 2.1.201, and the programmatic invocation succeeded. From there I should be able to verify before and after states that I expect with my custom MSBuild tasks.

coder8keyboard commented 6 years ago

Either update obj/project.assets.json to reference new framework or delete profile and re-create the profile. Assumptions: -Upgraded project from netcore2.0 to 2.1 -The error encountered when you try to publish using an existing profile.

Undevd commented 6 years ago

I was getting a similar error after updating my projects frameworks. I noticed in my publish profile file(Properties/PublishProfiles/*.pubxml) that the TargetFramework hadn't been updated to reflect the new framework. Changing manually in here or simply running through the configure option on my publish tab resolved the issue for me.

6pac commented 6 years ago

@zeroish updating 'Properties/PublishProfiles/*.pubxml' worked for me. I was having the issue on windows, without resharper, VS 2017 15.7.4

arivera12 commented 6 years ago

@Altiss solutions worked for me!

sharushetty commented 5 years ago

I got this very same error on project.assets.json when I had converted a .Net 4.5 Class Library project to target multiple .Net Frameworks by manually updating the csproj file. After trying out almost all the solutions listed in this page, the fix that worked for me was to remove the below line from csproj which I had accidentally left:

\<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" \/>

dybzon commented 5 years ago

I'm curious if anyone on this thread is seeing the issue but does not have ReSharper installed and enabled.

I ran into this issue on a computer where I have not installed ReSharper. I first tried deleting the obj and bin folders and then re-publishing, but it wasn't until I upgraded VS to the latest version (15.9.4) that the issue went away.

I did not try restarting VS prior to upgrading it, so I cannot say whether a restart of VS would've solved the issue for me.

pbarranis commented 5 years ago

Same issue; editing .pubxml file manually was the only solution. VS 15.9.5; this happened when updating my project from .NET Core 2.1 to 2.2. Tried closing VS, deleting obj and bin folders, then re-opening, but that didn't fix it. Unlike an earlier comment, when I opened the Publish page, the "Target Framework" correctly showed "netcoreapp2.2", but when I opened the pubxml file, it was set to 2.1, not 2.2.

Never had Resharper installed.

I'm surprised a moderator kicked this over to NuGet. It's really the responsibility of NuGet to update Publish profiles when the project is restored with a newer version of .NET Core?

shidinh commented 5 years ago

In my case, I just had to rec-create my publish profile. That ensured everything was in sync.

Portekoi commented 5 years ago

Same issue on VS2019 Community and the solution of @dhieyson works for me.

raxuser100 commented 5 years ago

I am running Visual Studio 2019.

Deleting the obj and bin folders seems to work just fine. No need to update any other settings.

raxuser100 commented 5 years ago

I am running Visual Studio 2019.

1) Delete the obj and bin folders 2) Add line below to the csproj file, beneath the <TargetFramework>netcoreapp3.0</TargetFramework>

<RuntimeIdentifier>win-x64</RuntimeIdentifier>

3) Restart Visual Studio 4) Publish project

alexreich commented 4 years ago

Ran into w/2019 - even though all targets were changed to 3.0 and bin and objs were removed. The Publish profile was not changed and had to be manually modified: altering the pubxml file fixed the issue.

ghost commented 4 years ago

Add line below to the csproj file, beneath the \netcoreapp3.0\ \win-x64\

germanpa commented 4 years ago

as @alexreich said, check your PublishProfiles files they can target other target Framework if you are doing a migration PublishProfiles PublishProfiles2

DaveCousineau commented 4 years ago

Still an issue in VS2019 16.6. Reopening the solution fixed it.

omarhimada commented 4 years ago

I resolved this issue after trying absolutely everything in this thread (on the latest version of VS 2019 enterprise). It seems liked putting a project and solution in the same directory as the solution is no bueno. For example:

This is bad:

- Solution.sln
- Project.csproj
- Startup.cs
- Program.cs
- /OtherProject
    - OtherProject.csproj
    ...
...

This is good:

- Solution.sln
- /Project
    - Project.csproj
    - Startup.cs
    - Program.cs
- /OtherProject
    - OtherProject.csproj
    ...
...
JanEggers commented 4 years ago

Still an issue in VS2019 16.7.6

JesperBaltzersen commented 4 years ago

Having this issue in VS4Mac 8.7.9 (build 9)

ToanNguyen-SPCE commented 4 years ago

I suddenly got this issue even though it was working fine 5 minutes ago, VS Studio 8.7.9 (build 9) Mac OS

Yeasin-Ahmed commented 6 months ago

Nothing works for me but after updating the VS 22, fixed my issue.

Thanks all. :)

TheJakov commented 5 months ago

@alexvy86 Not sure this would help, but I had the same issue when trying to build net40 project after building netstandard2.0 project, and both projects files are in the same folder.

What resolves the issue for me is manually deleting the \obj\project.assets.json file, which tends to break the build for the net40 project, if present, with the following error: Your project is not referencing the ".NETFramework,Version=v4.0,Profile=Client" framework. Add a reference to ".NETFramework,Version=v4.0,Profile=Client" in the "frameworks" section of your project.json, and then re-run NuGet restore.

Hi @bsivanov, you mentioned manually deleting the \obj\project.assets.json file - which will do the job, works for me too.

You must have had some issues when taking these projects to some DevOps pipeline and trying to build. Have you tweaked pre-build/post-build events to delete \obj\project.assets.json file, or something similar?