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

alexvy86 commented 7 years ago

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

alexvy86 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@Altiss Thanks, this work for me too

vullnetyy commented 7 years ago

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 commented 7 years ago

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

@rainersigwald, this issue can be closed.

Thanks.

latchkostov commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@vullnetyy does this help? https://github.com/dotnet/sdk/issues/1321#issuecomment-323606946

vullnetyy commented 7 years ago

@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 commented 7 years ago

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

rsbeanbag commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

image

ocapio commented 7 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

livarcocc commented 6 years ago

This issue was moved to NuGet/Home#6482

nkolev92 commented 6 years ago

This conversation has gone a lot of different directions, so forgive me if I miss a scenario.

I've tested out 2 different scenarios, with the latest 15.6 P2 build.

1) Adding a new target framework in VS. Expected: Restore happens, targets in the project assets json are updated. Actual: Restore happens, the targets in the project.assets.json are not updated, however the package spec is updated. This is definitely a bug. Hint for later investigation, the originalTargetFrameworks are out of sync with the targetframeworkinformation.

2) Changing the output type from Exe to Library etc. Note that "NuGet" does not care directly what the output type is, the difference here is that some of the implied dependencies change in the netcore case when the output is changed. Other things such as a RuntimeIdentifiers are specified in the Exe case as well, which affects restore. Expected: Restore happens, targets in the project assets json are updated. Actual: Restore happens, targets in the project assets json are updated. No repro on this scenario.

Update:

This seems like it's a nomination issue.

BEGIN Nominate Restore for C:\Users\nikolev.REDMOND\Source\Repos\ConsoleApp21\ConsoleApp21\ConsoleApp21.csproj
    BaseIntermediatePath:     obj\
    OriginalTargetFrameworks: netcoreapp2.0; net461
    Target Frameworks (2)
        net45
            Project References
            Package References
            Target Framework Properties -- (RestoreAdditionalProjectFallbackFolders:;C:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\..\..\..\..\NuGetFallbackFolder | RestorePackagesPath: | MSBuildProjectDirectory:C:\Users\nikolev.REDMOND\Source\Repos\ConsoleApp21\ConsoleApp21 | RestoreAdditionalProjectSources: | PackageId:ConsoleApp21 | RuntimeIdentifier: | NoWarn:1701;1702;1705 | RestoreAdditionalProjectFallbackFoldersExcludes: | TargetFrameworkIdentifier:.NETFramework | VersionSuffix: | DotnetCliToolTargetFramework:netcoreapp2.0 | VersionPrefix:1.0.0 | BaseIntermediateOutputPath:obj\ | Version:1.0.0 | RestoreFallbackFolders: | MSBuildProjectFile:ConsoleApp21.csproj | TargetFrameworkMoniker:.NETFramework,Version=v4.5 | EmitAssetsLogMessages:true | TargetFramework:net45 | PackageTargetFallback: | TreatWarningsAsErrors:false | TargetFrameworkProfile: | RestoreSources: | TargetFrameworks:netcoreapp2.0; net461 | TargetFrameworkVersion:v4.5 | RuntimeIdentifiers: | PackageVersion:1.0.0 | WarningsAsErrors:NU1605 | AssetTargetFallback:)
        netcoreapp2.0
            Project References
            Package References
                Microsoft.NETCore.App -- (Description: | RuntimeIdentifier: | NoWarn: | OriginalItemSpec: | FrameworkName: | Version:2.0 | Visible: | TargetFramework: | IncludeAssets: | PrivateAssets:All | ExcludeAssets: | IsImplicitlyDefined:true | FrameworkVersion: | Name: | Type: | Path:)
            Target Framework Properties -- (RestoreAdditionalProjectFallbackFolders:;C:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\..\..\..\..\NuGetFallbackFolder | RestorePackagesPath: | MSBuildProjectDirectory:C:\Users\nikolev.REDMOND\Source\Repos\ConsoleApp21\ConsoleApp21 | RestoreAdditionalProjectSources: | PackageId:ConsoleApp21 | RuntimeIdentifier: | NoWarn:1701;1702;1705 | RestoreAdditionalProjectFallbackFoldersExcludes: | TargetFrameworkIdentifier:.NETCoreApp | VersionSuffix: | DotnetCliToolTargetFramework:netcoreapp2.0 | VersionPrefix:1.0.0 | BaseIntermediateOutputPath:obj\ | Version:1.0.0 | RestoreFallbackFolders: | MSBuildProjectFile:ConsoleApp21.csproj | TargetFrameworkMoniker:.NETCoreApp,Version=v2.0 | EmitAssetsLogMessages:true | TargetFramework:netcoreapp2.0 | PackageTargetFallback: | TreatWarningsAsErrors:false | TargetFrameworkProfile: | RestoreSources: | TargetFrameworks:netcoreapp2.0; net461 | TargetFrameworkVersion:v2.0 | RuntimeIdentifiers: | PackageVersion:1.0.0 | WarningsAsErrors:NU1605 | AssetTargetFallback:;net461)
    Tool References

------------------------------------------
COMPLETED Nominate Restore for C:\Users\nikolev.REDMOND\Source\Repos\ConsoleApp21\ConsoleApp21\ConsoleApp21.csproj

Note that OrignalTargetFrameworks is "net461".

Target Frameworks is net45.

The action that I did was changing net45 to net461.

//cc @natidea @emgarten

livarcocc commented 6 years ago

If this is a nomination problem, it belongs in dotnet/project-system, not at the SDK.

@natidea or @Pilchie can you confirm?

natidea commented 6 years ago

I've created an issue in Project to track this: https://github.com/dotnet/project-system/issues/3182 May also be related to https://github.com/dotnet/project-system/issues/2657

sathyam-kgb commented 6 years ago

I removed the following configuration in the csproj file:

`

AnyCPU

`

Along with

<RuntimeIdentifier>%Platform%</RuntimeIdentifier>

I am passing the Platform setting when calling MSBuild with: /p:Platform="Any CPU"

Making these changes helps me build in VS as well as my msbuild scripts

dhieyson commented 6 years ago

In my case showed this error when publishing: C:\Program Files\dotnet\sdk\2.1.102\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(167,5): Error : Assets file 'C:\Myproject\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.

I tryed every restore options but not function.

To solution my problem i deleted folder "C:\Program Files\dotnet\sdk\2.1.102". After that i published again with success

carstenschaefer commented 6 years ago

@dhieyson this fixed it for me, too. Had this problem after upgrading my VS2017 this morning to newest version.

ghost commented 6 years ago

Also, the solution posted by @dhieyson worked for me. Nothing else posted in this thread. The problem has occurred after the installation of the newest version of VS.

RomeDev commented 6 years ago

I had the same problem after updating my VS today! Solution posted by @dhieyson solved this issue for me. Thanks!

cemilf commented 6 years ago

@dhieyson 's solution solved my problem too. dotnet sdk 2.1.102 seems to be the problem.

Thorarin commented 6 years ago

To be clear, the latest version at the time of writing is VS2017 15.6.3. I'm having the same issue and the workaround posted by @dhieyson also worked for me.

yesitspeter commented 6 years ago

Same issue here as @RomeDev describes. 15.6.3. Deleting the "C:\Program Files\dotnet\sdk\2.1.102" also worked for me. I had to do a repair install after this update as well, as the Package Manager Console stopped working (displayed an exception)

brentlyjdavid commented 6 years ago

+1, this is a substantial productivity impact

chassq commented 6 years ago

+1, same issue here. Removing sdk 2.1.102 folder in "C:\Program Files\dotnet\sdk" did fix it...

redowl3 commented 6 years ago

I had the same problem after updating my VS today, solution posted by @dhieyson solved this issue for me also. Thanks.

Suspect there will be another update to VS very shortly.

steffenloesch commented 6 years ago

+1, we also ran into this issue after upgrading to 15.6.3, in our case with target framework uap10.0.

Itoktsnhc commented 6 years ago

I had the same problem after updating VS to 15.6.3

marceloatg commented 6 years ago

+1, Same problem after updating VS to 15.6.3 both on windows 10 x64 and windows server 2016 x64 (Resharper enabled on both). Removing sdk 2.1.102 as posted by @dhieyson also solved for me, however I had to download manually the sdk 2.1.101 and repair it due to colateral damage of my other attempts to solve the issue.

hughbiquitous commented 6 years ago

MSFT suggested I disable ReSharper, and indeed, that works around the problem... but coding without ReSharper... no thanks.

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

mjolka commented 6 years ago

I was able to go back to Visual Studio 15.5.7 following the instructions here: https://docs.microsoft.com/en-us/visualstudio/productinfo/installing-an-earlier-release-of-vs2017

That fixed the problem for me, even after reinstalling ReSharper.

yesitspeter commented 6 years ago

@mjolka Thank you for that link.

pogliad commented 6 years ago

Had same problem when ReSharper is enabled. The solution posted by @dhieyson worked for me (https://github.com/dotnet/sdk/issues/1321#issuecomment-374706295). I removed "C:\Program Files\dotnet\sdk\2.1.102" and all is Ok. But what is the source of problem?

I found report on MS Developer Community forum https://developercommunity.visualstudio.com/content/problem/218434/after-updating-to-the-new-version-my-corenet-proje.html

Our initial investigation show that this only repros if ReSharper is installed. Disabling ReSharper extension seems to fix this issue. We are still investigation the root cause. We hope to release an update with the fix soon. Thanks for your patience.

risfeng commented 6 years ago

I'm the same problem. Probably caused by the installation of the ReSharper plug-in, my solution is to use ReSharper build, set ReSharper build: ReSharper-> Tools -> Build & Run. This solves my problem, may wish you also try. Edit: VS15.6.4 have been repaired.