12
votes

I have a preexisting ASP.NET Core 3.0 application which is successfully deployed to an Azure App Service (using the AspNetCoreModuleV2 module). After upgrading the app to (today's release of) ASP.NET Core 3.1, the application builds and runs correctly on my local version of IIS Express. When I attempt to publish to the Azure App Service using (today's release of) Visual Studio 16.4, however, I receive the following error:

Assets file 'C:\Project\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project.

Notes

  • All <PackageReference>'s to Microsoft.AspNetCore, Microsoft.EntityFrameworkCore, and Microsoft.Extensions have been updated to 3.1.0
  • I have cleaned my solution, and even nuked my obj folder to ensure there aren't any lingering references.
  • This error is being generated from the 3.1.100 version of Microsoft.PackageDependencyResolution.targets.

I get that something is still hanging onto the .NET Core 3.0 dependencies. But it's unclear why that's only causing problems during deployment. Are Azure App Service's not yet ready for .NET Core 3.1? Or is this an issue with the dependency resolution targets?

4
The docs show how to explicitly select the .NET Core SDK version. Have you tried that? Does the 3.1 SDK appear in the list?Panagiotis Kanavos
@PanagiotisKanavos: This project isn't published using Azure Pipelines yet. That said, this does remind me that there's also a <TargetFramework> setting in the pubxml profile that Visual Studio relies on, which I spaced on. Oops! Changing that to netcoreapp3.1 to match the csproj target resolves the immediate issue. (This introduces a new issue with Azure App Service itself tripping on the target, but that can probably be resolved by using a self-contained deployment, similar to the link you provided.) Thank you for pointing me in the right direction!Jeremy Caney
Aah, timezone differences ...Panagiotis Kanavos
Well thank goodness for finding this question (and answer). I am starting to get pretty frustrated with adopting bleeding edge MS changes (on their recommendation and encouragement) only to keep running into issues like this.Frank

4 Answers

16
votes

The immediate issue—as identified in the original question—has to do with there being two places where <TargetFramework> is set:

  1. The project file (e.g., csproj)
  2. The publishing profile (i.e., pubxml)

The <TargetFramework> must be updated in both locations, and they must match exactly. Otherwise, the publishing won't be able to find its targets in the project.assets.json file, which is built based on the <TargetFramework> in the csjproj file.

Note: You may well expect the pubxml file to defer to the <TargetFramework> set in the csproj file, but that is not the case.

Text Editor

To make this modification via a text editor,

  1. Open the ~/Properties/PublishProfiles folder.
  2. Open the *.pubxml you wish to edit.
  3. Modify the value of <TargetFramework> to netcoreapp3.1:
<TargetFramework>netcoreapp3.1</TargetFramework>

Visual Studio 2019

To make this modification via the Visual Studio 2019 IDE,

  1. Click the gear icon on the Web One Click Publish toolbar (it's to the right of the publish icon).
  2. Assuming the Target Framework is not set to netcoreapp3.1, click the edit icon next to it.
  3. Ensure that the Target Framework is set to netcoreapp3.1.
  4. Click Save.

Warning: When using the IDE, you may run into a problem here. When editing the profile you'll likely see the new value from your project file (i.e., netcoreapp3.1) already selected. When you click Save, however, it will revert back to the original value (e.g., netcoreapp3.0 in my case). This is because you didn't actually change the value in the interface, which Visual Studio mistakes for there not being a change to the underlying values. If you temporarily toggle another value (e.g., Configuration), then Visual Studio will recognize that a change has occurred, and both values will be updated in the *.pubxml file.

Thank you, again, to @PanagiotisKanavos for pointing me in the right direction (see comments on original thread).

2
votes

Open Project folder;

  • Navigate to folder Properties>>PublishProfiles
  • Open file FolderProfile.pubxml then change version 3.0 to 3.1

    netcoreapp3.1

  • Finally, rebuild your application before publishing

1
votes

I got this error from a fresh new net5.0 project in VS2019 (ASP.NET Core Web Application template) when using the VS web-publisher. The solution is as follows:

  1. Open file: {project}\Properties\PublishProfiles\{project} - Web Deploy.pubxml

  2. Add the following line inside the <PropertyGroup> element:

    <TargetFramework>net5.0</TargetFramework>

The element was missing entirely - great work MS

0
votes

change

<PackageReferenceInclude="Microsoft.AspNetCore"Version="2.2.0" />
 to 
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />

works for me.