Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rainersigwald opened this issue Jun 8, 2017 · 89 comments

Comments

@rainersigwald
Copy link
Member

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: dotnet/msbuild#2196

@alexvy86
Copy link
Contributor

@rainersigwald did you figure this out? I'm seeing the same error trying to build a simple console app that targets net451 and netcoreapp1.1

@bsivanov
Copy link

bsivanov commented Jul 27, 2017

@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.

@alexvy86
Copy link
Contributor

Thanks @bsivanov. I did try some variations of that but couldn't get it to work. To be sure I understood correctly: you have 2 separate project files, each one targeting a different framework, correct? For completeness sake in the discussion, in my case there's just one project which multi-targets net451 and netcoreapp1.1.

@bsivanov
Copy link

bsivanov commented Jul 27, 2017

@alexvy86 yes, you get me right, but apparently your problem is different. You can maybe try to split the multi-targeting project to two projects, just to check whether the issue is related to some problematic leftover in the project.assets.json. Or maybe try to change the order in <TargetFrameworks>, if it matters at all?

@alexvy86
Copy link
Contributor

I'm trying that as well (separate the projects) and ran into different errors that don't seem related. If I figure this out I'll post an update here.

@vullnetyy
Copy link

I have a .NET Standard 2.0 project and a .NET Framework 4.6.1 project in the same solution. When I try to build the 4.6.1 project, VS2017 shows the following error: Assets file 'C:\mySolution\dotnetFrameworkProject\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v4.6.1'. Ensure that restore has run and that you have included 'net461' in the TargetFrameworks for your project.

in

C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets 165

I tried deleting the project.assets.json file but the regenerated file didn't do me any good. I searched the project.assets.json file for the string TargetFrameworks (case insensitive) and only found a key called originalTargetFramework.

Any ideas?

@patroza
Copy link

patroza commented Aug 20, 2017

Adding <RuntimeIdentifier>win7-x64</RuntimeIdentifier> to the csproj, beneath the <TargetFramework>net462</TargetFramework> seems to work.

(hm this seems to be a fix for another flavour of the same problem :))

@codegenic-works
Copy link

I encountered a similar error after updating my solution with multiple 1.1 projects to 2.0. I just deleted the bin and obj folders in each project and rebuilt. I no longer get the error.

@RoCore
Copy link

RoCore commented Aug 28, 2017

@altiss Thanks, this work for me too

@vullnetyy
Copy link

Deleting the obj and bin folders did not work for me. However I did manage to fix my issues using
dotnet restore mysolution.sln after getting the latest versions of Visual Studio 2017 and .NET Core 2

@kosa-gyula-77
Copy link

The issue cannot be reproduced after updating Visual Studio Professional 2017 to Version 15.3.2.

@rainersigwald, this issue can be closed.

Thanks.

@latchkostov
Copy link

@kosa-gyula-77 I disagree, I just ran into this issue on 15.3.2, when trying to upgrade an application from netcoreapp1.1 to netcoreapp2.0. I had to delete the contents of the obj folder.

@vullnetyy
Copy link

What we've discovered now is that when we have .NET Core SDK 2.0 installed, we cannot build .NET Framework 4.6.1 projects with the new .csproj format. We keep getting the ...obj\project.assets.json... error

@patroza
Copy link

patroza commented Aug 31, 2017

@vullnetyy does this help? #1321 (comment)

@vullnetyy
Copy link

@patroza Do you mean the <RuntimeIdentifier>win7-x64</RuntimeIdentifier>? No. We did try moving to 4.6.2 and placing it beneath TargetFramework and it didn't work anyway. Thanks for trying.

@jgauffin
Copy link

I get the same error. Also, when updating <targetFrameworks> by changing targets the project.assets.json doesn't seem to sync the changes.

@rsbeanbag
Copy link

rsbeanbag commented Sep 27, 2017

I 'm converting .net framework projects to the 'new' format and stumbled into this very problem. When
I add <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> to the .csproj then my project compiles and runs as expected.

It's an ugly solution of course but maybe it will help explain why this problem occurs?? (and how to solve this properly)

ps. I have not tried this with a .Net Core project.

@pbechtelGitHub
Copy link

Changing TargetFramework to TargetFrameworks worked for me for Core 2.0 Console app.
https://stackoverflow.com/questions/42842443/asp-net-core-application-net-framework-for-windows-x64-only-error-in-project

@Juslwk
Copy link

Juslwk commented Oct 6, 2017

I encounter this issue when publishing. Weird because I can publish successfully to my development environment, but publishing to production environment fails. Both environments are hosted in Azure as App Services and I am using Azure click-once deployment. I tried changing TargetFramework to TargetFrameworks, and deleted the project.assets.json file without success.
In the end, the way I fix it was, I modified the Development publish profile and changed my connection details to point to the production. After that it publishes successfully.

@Judgeja
Copy link

Judgeja commented Oct 16, 2017

I had the same as @Juslwk. I realised my publish profile was still targeting 1.1, even though 2.0 was showing as selected when I went into edit the profile, it showed 1.1 in the publish summary. So I re-selected 2.0 in the dropdown and it updated the summary to show 2.0 and it all worked fine

@daveaglick
Copy link

This happened to me when I manually edited a csproj file to go from:

<TargetFrameworks>netstandard1.6</TargetFrameworks>

To:

<TargetFrameworks>net46;netstandard1.6</TargetFrameworks>

I tried everything suggested here and the project.assets.json file just kept coming back the same. It wasn't until I closed Visual Studio, deleted the obj folder, and reopened Visual Studio that the restore created a new project.assets.json file with the targeting changes. I suspect the NuGet process in VS must be caching the packages somewhere in memory and won't regenerate the file just for targets changes.

@rainymaplesoft
Copy link

rainymaplesoft commented Oct 30, 2017

I got the same problem after I changed the target from net452 to net461, when I ran publish it complained the project was not compatible with net452 etc, even the target framework was set to net461 in the publish profile. BUT, I happened to find the TargetFramwork was still "net452" in the publish summary page, even in the "Setting" it was set to net 461. It was very wired. The solution then became very simple: Delete the publish profile, then create a new one with setting the target framework to that you want. Error is gone.

@rainymaplesoft
Copy link

rainymaplesoft commented Oct 30, 2017

image

@ocapio
Copy link

ocapio commented Oct 31, 2017

@daveaglick I am running into a similar issue since I updated to Visual Studio 2017 15.4.1. It seems like reinstalling Visual Studio seems to fix this. I would like to find a solution to this since other machines may be affected by this.

@memark
Copy link

memark commented Nov 26, 2017

I ran into this today, in Visual Studio 15.4.4. I had edited the project file within VS (using right click / Edit) and changed the OutputType.

The solution was to unload/reload the project in VS. It seemed VS did not honour the file change otherwise and instead gave the above error about frameworks.

@tameyer1
Copy link

Just ran into this, read through the comments here, and was able to resolve.
I have a core 2.0 library project. I edited the csproj file to add .net45 to targetframeworks. Upon compiling I was getting the Assets file error mentioned above. Tried deleting bin and obj directories and recompiling. This did not work.

Simply did an unload and reload of the project as @memark mentioned. First compile didnt work but I suspect the restore was still running. Once it finished I rebuilt to success. Hope it helps and thanks to the commentators above.

@livarcocc
Copy link
Contributor

This issue seems to be related to how restore happens in visual studio after project changes. As such, I will move it to NuGet.

@nhustak
Copy link

nhustak commented Jun 17, 2018

The solution from @tunechr fixed my issue.

@mwpowellhtx
Copy link

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
Copy link

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

@mwpowellhtx
Copy link

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
Copy link

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
Copy link

Undevd commented Jul 27, 2018

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
Copy link

6pac commented Aug 3, 2018

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

@arivera12
Copy link

@altiss solutions worked for me!

@sharushetty
Copy link

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
Copy link

dybzon commented Dec 26, 2018

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
Copy link

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
Copy link

shidinh commented Apr 24, 2019

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

@Portekoi
Copy link

Portekoi commented Oct 4, 2019

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

@raxuser100
Copy link

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
Copy link

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>

  1. Restart Visual Studio
  2. Publish project

@alexreich
Copy link

alexreich commented Nov 20, 2019

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
Copy link

ghost commented Dec 25, 2019

Add line below to the csproj file, beneath the <TargetFramework>netcoreapp3.0</TargetFramework>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>

@germanpa
Copy link

germanpa commented Feb 4, 2020

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

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
…0200305.1 (dotnet#1321)

- Microsoft.AspNetCore.Analyzers - 5.0.0-preview.2.20155.1
- Microsoft.AspNetCore.Components.Analyzers - 5.0.0-preview.2.20155.1
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 5.0.0-preview.2.20155.1
- Microsoft.AspNetCore.Mvc.Analyzers - 5.0.0-preview.2.20155.1
@DaveCousineau
Copy link

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

@omarhimada
Copy link

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
Copy link

Still an issue in VS2019 16.7.6

@JesperBaltzersen
Copy link

Having this issue in VS4Mac 8.7.9 (build 9)

@ToanNguyen-SPCE
Copy link

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
Copy link

Yeasin-Ahmed commented Apr 18, 2024

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

Thanks all. :)

@TheJakov
Copy link

TheJakov commented Jun 8, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests