get error Assets file 'obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2'
Asked Answered
C

6

14

I upgrade my MVC Core Project from 2.2 to 3.0 with microsoft

and change many recommended here: https://stackoverflow.com/

It works fine when run it in Local, but when I want publish in local folder I get this error :

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

Ii have 3 projects and all of them upgrade to MVC core 3.0 also upgrade all packages to 3.0 also remove object folder and bin folder and build projects again, close VS and open it again but the error stil exists.

UPDATE: mvc project csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
  <TargetFramework>netcoreapp3.0</TargetFramework>   
</PropertyGroup>

<ItemGroup>
 <!--<PackageReference Include="Microsoft.AspNetCore.App" />-->
  <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0" 
 />      
   <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" 
Version="3.0.0" />
</ItemGroup>

<ItemGroup>
  <Folder Include="Areas\Admin\Data\" />
  <Folder Include="Areas\Admin\Models\" />
 </ItemGroup>

<ItemGroup>
  <ProjectReference Include="..\project.Model\project.Model.csproj" />
  <ProjectReference Include="..\project.Repo\project.Repo.csproj" />
</ItemGroup>

</Project>

My project.Model.csproj

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
  <TargetFramework>netcoreapp3.0</TargetFramework>  
</PropertyGroup>

<ItemGroup>
  <PackageReference 
Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" 
 Version="3.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; 
   buildtransitive</IncludeAssets>
  </PackageReference>
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" 
 Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" 
 Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" 
 Version="3.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; 
 buildtransitive</IncludeAssets>
 </PackageReference>
 </ItemGroup>

 </Project>
Contentious answered 13/11, 2019 at 22:18 Comment(2)
Can you post your csproj file content ?Doherty
Update question and post my .csproj filesContentious
D
11

In our case we had a very similar error when Publishing, after switching from netcoreapp30 to netcoreapp31 as the target Framework. We solved it by:

  1. Closing Visual Studio
  2. Deleting the file \obj\project.assets.json
  3. Opening the solution again
  4. Rebuild Solution

After that we were able to Publish the project fine.

Discotheque answered 3/6, 2020 at 11:57 Comment(2)
This is very common for me when one branch is on a different version. When switching branches with different versions, deleting the obj folder and restarting VS resolves my issue.Sit
Thank god for SO. I had erased the json file but had not closed and opened the solution. So bizarre!Plumate
S
7

Make sure your Publish Profile says netcoreapp3.0 for the TargetFramework.

Shrewd answered 22/11, 2019 at 21:3 Comment(2)
This was my issue. I upgraded from .netcore 2.2 to 3 and my publish profile did not get updated. Even though the UI said that it was targeting .netcore 3.1, it was not. I went and looked at the .pubxml file and it still had .netcoreapp2.2 which was not reflected using the publish configuration UI.Melchizedek
@Melchizedek mine issue is solved by your comment descriptionAllege
R
4

In your Package Manager Console run the following command: dotnet restore SolutionName.sln

Rebut answered 17/1, 2020 at 20:11 Comment(1)
Worked great for me, thanks! Interestingly, the console raised an error message "MSBUILD : error MSB1009: Project file does not exist." (and keeps raising it) but the solution still builds fine after that.Isomerize
E
1

This happens usually when you upgrade the .net core version. The solution is to create new publish profile. Not edit, simple create new publish profile and target the new .net core version that you have upgraded.

Electrograph answered 8/5, 2020 at 2:35 Comment(1)
I Had similar issue , Updating Publish profile settings to correct >net version solved the issue.Heartfelt
L
1

If you are doing this in a lambda then make sure to update aws-lambda-tools-defaults.json and serverless.template files.

Loosestrife answered 23/7, 2021 at 20:54 Comment(0)
D
0

If you run publish with the command line (dotnet publish), make sure you specified the correct framework with option "-f".

Dedra answered 2/8, 2021 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.