Netcore 2.1.1 release leads to app failing to run - asp.net-core

It seems there is suddenly something out of sync with asp.net core packages.
It looks like Microsoft.AspNetCore.App 2.1.1 was released 16 hours ago on nuget.org but only 158 downloads, and apparently I'm one of the downloaders.
My .csproj file is like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\cloudscribe.Web.Navigation\cloudscribe.Web.Navigation.csproj" />
<ProjectReference Include="..\cloudscribe.Web.SiteMap\cloudscribe.Web.SiteMap.csproj" />
<ProjectReference Include="..\cloudscribe.Web.SiteMap.FromNavigation\cloudscribe.Web.SiteMap.FromNavigation.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.*" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.*" />
</ItemGroup>
</Project>
It builds but when I try to run it I get:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.1' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
- The following versions are installed:
2.1.0 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
If I change my version for Microsoft.AspNetCore.App to 2.1.0 and do dotnet restore I get this:
C:_c\cloudscribe.Web.Navigation\src\NavigationDemo.Web\NavigationDemo.Web.csproj : error NU1107: Version conflict detected for Microsoft.AspNetCore.Antiforgery. Reference the package directly from the project to resolve this issue.
C:_c\cloudscribe.Web.Navigation\src\NavigationDemo.Web\NavigationDemo.Web.csproj : error NU1107: NavigationDemo.Web -> cloudscribe.Web.Navigation -> Microsoft.AspNetCore.Mvc.Razor 2.1.1 -> Microsoft.AspNetCore.Mvc.ViewFeatures 2.1.1 -> Microsoft.AspNetCore.Antiforgery (>= 2.1.1)
C:_c\cloudscribe.Web.Navigation\src\NavigationDemo.Web\NavigationDemo.Web.csproj : error NU1107: NavigationDemo.Web -> Microsoft.AspNetCore.App 2.1.0 -> Microsoft.AspNetCore.Antiforgery (= 2.1.0).
Restore failed in 3.54 sec for C:_c\cloudscribe.Web.Navigation\src\NavigationDemo.Web\NavigationDemo.Web.csproj.
I suppose that is partly due to the other projects in my solution with dependencies like this:
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.*" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.1.*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.1.*" />
There does not seem to be an updated sdk for 2.1.1 but the availability of Microsoft.AspNetCore.App 2.1.1 on GitHub seems to be breaking things for me.

The 2.1.1 (preview) SDK is available on their GitHub.
You can download directly here:
https://dotnetfeed.blob.core.windows.net/orchestrated-release-2-1/20180605-09/final/assets/Sdk/2.1.301-preview-008906/dotnet-sdk-2.1.301-win-x64.exe
See:
https://github.com/dotnet/versions/tree/7a833dddfddc27f2074b755b94234a25b9757637/build-info/dotnet/product/cli/release/2.1
We are still waiting on the official SDK...
Edit:
If you are having trouble building, add the following to your .csproj
<PropertyGroup>
<TargetLatestAspNetCoreRuntimePatch>true</TargetLatestAspNetCoreRuntimePatch>
</PropertyGroup>
Update:
Official 2.1.1 SDK now released: https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.1.301-windows-x64-installer

Your problem is this line of your csproj:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.*" />
The * is saying to pick the latest 2.1 version of that NuGet package. For many packages, this would be perfectly fine. However, v2.1.1 of that package requires a matching v2.1.1 SDK to also be installed. As of right now, it is not available (it's currently blocked).
However, if you read the Migrate from ASP.NET Core 2.0 to 2.1 docs, you will see this:
Replace the version specified "Microsoft.AspNetCore.All" package reference with the versionless "Microsoft.AspNetCore.App" package reference.
The version is now inferred by the version of the SDK you are targeting. This means your csproj should now contain this:
<PackageReference Include="Microsoft.AspNetCore.App" />

In addition to other suggestions, I needed to up the Microsoft.NetCore.App to 2.1.1. Since I couldn't do it via the UI, adding the following to the .csproj worked.
<PackageReference Include="Microsoft.NetCore.App" Version="2.1.1" />

I had the same issue. Another option is, in NuGet Package Manager, rollback Microsoft.AspNetCore.All, Microsoft.AspNetCore.Rewrite, and Microsoft.NETCore.App to versions 2.1.0.

The wildcard version number package references is weird to me. That doesn't happen by default, so either you or one of your team members did that. I don't know if that's the source of at least some of your issues or not, but I'd start by changing them to full version references. NuGet packages are not committed with your project, so having wildcards can lead to strange build issues, particularly in automated builds, when you're developing against one version but a different version is restored later. If you want to upgrade a package, that should be an explicit choice, so you can then verify that all your code still functions as it should post-upgrade.
Also worth noting, since 2.1, code generation has been rolled in, so you should not be explicitly referencing any CodeGen packages.
As far as solving the current issue goes. You may be having some issues with your package cache. In Visual Studio, go to Tools > NuGet Package Manager > Package Management Settings, and then click the "Clear All NuGet Cache(s)" button.
That should prompt a redownload of all your projects NuGet packages, and may be enough to solve the issue. If not, I'd recommend cleaning all your projects and then going into the directory for each and manually deleting both the bin and obj directories. Then, rebuild your solution.

For bugged SDK 2.1.301 version use:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
and force all other packages 2.1.1 -> 2.1.0.

Installing 2.1.301 (https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.1.1-download.md) fixed this issue for me.

Related

Can't create EF migrations after installing .NET 6

I've just installed .NET 6 SDK and updated all my projects to use target net6.0, but when I try to create a new migration with the dotnet tool I get:
.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationIcon>assets-logo.ico</ApplicationIcon>
<RootNamespace>LC.Assets</RootNamespace>
<Authors>Stein Lundbeck</Authors>
<Company>Lundbeck Consulting</Company>
<Product>LC Assets</Product>
<Copyright>2021</Copyright>
</PropertyGroup>
<ItemGroup>
<Content Include="assets-logo.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LC.Components.Core\LC.Components.Core.csproj" />
<ProjectReference Include="..\LC.Components\LC.Components.csproj" />
</ItemGroup>
</Project>
It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
The following frameworks were found:
6.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
I've updated the dotnet-ef tool to version 6.0.0, so I don't know what it is that still target the 2.0.0 version.
Tool 'dotnet-ef' was successfully updated from version '5.0.4' to version '6.0.0'.
Any ideas?
I just ran into the exact same issue.
Rather than installing Microsoft.NETCore.App 2.0.0., I installed the Entity Framework Core Design package:
dotnet add package Microsoft.EntityFrameworkCore.Design
It made the error go away for me.
Note: I came upon the solution after remembering that following the EF Getting Started guide (https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=netcore-cli) had me install the Design package and didn't throw the error when I followed the guide.
I had this problem recently after upgrading to .NET6.
The solution for me was to follow the link in the error message and install Microsoft.NETCore.App 2.0.0.
https://dotnet.microsoft.com/download/dotnet/2.0/runtime
I'm guessing that the upgrade to 6 removed this framework as it is considered legacy ... BUT ... is still used (or marked as a required dependency somehow) in the dot net tools.
The solution for me was installing EntityFrameworkCore.Design as suggested by #Thomas Z.
dotnet add package Microsoft.EntityFrameworkCore.Design
As well, making sure the path of the db is correct when creating the ef migration. It won't work if the path is dynamically created.

Cannot find `SignalR` in `Microsoft.AspNetCore.App` in .NET Core 2.2?

I'm not so sure why this can be a problem, I've just revised some documentation about SignalR in ASP.NET Core and it seems to mean that I don't have to install any additional package (already have Microsoft.AspNetCore.All and Microsoft.AspNetCore.App referenced after creating a new ASP.NET Core project (version 2.2).
I've even tried Googling and found this blog post: https://wakeupandcode.com/real-time-asp-net-core-web-apps-with-signalr/#dep
It was written on Dec 23 2018, and the author does confirm that we don't need to install any additional package.
Well so it's really playing on me, making me have a feeling of being stupid, not so sure why I cannot use SignalR in my project (I'm not intending to install any additional package, which I think should work for me), just wonder why it's not already available. The following code does not compile:
using Microsoft.AspNetCore.SignalR;
It reports that SignalR does not exist in the namespace Microsoft.AspNetCore right in the project that has Microsoft.AspNetCore.All and Microsoft.AspNetCore.App.
Actually I cannot find the Microsoft.AspNetCore.SignalR when expanding the references tree.
The documentation says nothing about where to import the module (which means it should already be available). As I said the project targets .NET Core 2.2. Could you explain to me something could be wrong here?
PS: My project is a Web API (not MVC) project.
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
</ItemGroup>
Usually, project templates have outdated libraries. Use the NuGet package manager to update references to recent versions and try again. It should help.

What is the default version of the nuget package when referenced with PackageReference in .NET Core project?

I am trying to learn and understand nuget and msbuild in .NET Core by examining and manually editing project files (.csproj in .NET Core 2.2).
So when I create WebApi project, the .csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Notice that there is no Version attribute specified for the first PackageReference.
Now if I specify it to be the latest stable version 2.2.3 like this:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.3" />
I get build warning NETSDK1071 which says:
A PackageReference to 'Microsoft.AspNetCore.App' specified a Version
of 2.2.3. Specifying the version of this package is not recommended.
For more information, see https://aka.ms/sdkimplicitrefs
This warning is not shown when Version attribute is omitted so I was wondering how is nuget package Version resolved when not set explicitly?
Also, how does dotnet build knows which version of a nuget package is recommended with the current project settings?
From the link in the warning, you can learn that it is not a regular package, but Meta-package.
It's mean that this package depends on your TargetFramework, and this is mean that when you target to a specific framework that installed in your machine (as SDK), the package will be taken from the specific SDK.

Build error of ASP.NET Core - "...current settings, version 2.1.0-preview3-26411-06 would be used instead"

I've created a sample project using dotnet, but I get the following error when building the project:
error : The project was restored using Microsoft.NETCore.App version 2.1.0-rc1, but with current settings, version 2.1.0-preview3-26411-06 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore.
What's the problem? I'm using Visual Studio 2017 build 15.7.0.
I had a similar error message:
The project was restored using Microsoft.NETCore.App version 2.0.7, but with current settings, version 2.0.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore
I added the RuntimeFrameworkVersion setting to the .csproj file, and it fixed an issue for me:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.7</RuntimeFrameworkVersion><!--here is the fix-->
</PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.7" />
</ItemGroup>
It seems Visual Studio is using different .NET Core versions for restore/build/publish.
To resolve this issue, you could add TargetLatestRuntimePatch attribute in the .csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
For details, please see this page.
In my case, in the .csproj file I changed
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
</ItemGroup>
to:
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" />
</ItemGroup>
And it worked.
I’ve installed .NET SDK 2.2.0 and found out that this isn't the correct version and the correct one was renamed to 2.1.300 to be in sync with the .NET Core application whose the last version is 2.1.0. I installed 2.1.300 and everything runs correctly.
Just because you have the latest SDK installed doesn't mean you have the latest runtime installed. I'll never quite understand that.
Run dotnet --info.
I got the following (only the latest installed versions are shown here).
.NET Core SDKs installed:
2.1.300 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:d\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
So I installed 2.1.1 runtime, and now dotnet --info gives me 2.1.1 as well.
Oh and 2.1.3 actually is 2.1.1, but they had to increment it for some reason I don't fully understand about or care about.
I restarted Visual Studio, because it never seems to be able to keep versions in sync
I added the following to PropertyGroup in my .csproj file (unload project + edit)
netcoreapp2.1
2.1.1
Now I thought we didn't need to specify this this any more, and this .csproj file was just created brand new today and it didn't have a runtime version at all. Whatever we're supposed to be doing, this worked for me. I also found this massive thread about versioning with 2.1.1 which I skimmed over, but it seems there are complications with point releases right now, so maybe this specific version is necessary.
I ended up here because of this error:
error : The project was restored using Microsoft.NETCore.App version
2.1.1, but with current settings, version 2.1.0 would be used instead. To resolve this issue, make sure the same settings are used for
restore and for subsequent operations such as build or publish.
Typically this issue can occur if the RuntimeIdentifier property is
set during build or publish but not during restore.
Adding RuntimeFrameworkVersion was the specific fix for that that worked.
Unfortunately there isn't any linked article for this error message, which would be helpful.
Use:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<UserSecretsId>aspnet-...............245435</UserSecretsId>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" />
</ItemGroup>
</Project>
In my case the issue was fixed by ensuring I had two projects, with one depending on the other.
One project had a RuntimeIdentifier specified in the .csproj file, but the other did not. Once I ensured both had matching RuntimeIdentifiers, the problem was fixed.
The specific error I was getting was
error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.0.5, but with current settings, version 2.1.1 would be used instead.
I had
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
</ItemGroup>```
further down the file. Once I removed this and did a clean, the project built successfully.
I have a somehow different solution, working for ASP.NET 2.1, as I had problems with both building and publishing processes:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion> --> fix publishing issues
<PlatformTarget>AnyCPU</PlatformTarget> --> fix publishing issues
</PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" /> --> fix building issues
<ProjectReference Include="..\PublicSonar.Monitor.Persistent.Json\PublicSonar.Monitor.Persistent.Json.csproj" />
</ItemGroup>
</Project>
I experienced the same:
The project was restored using Microsoft.NETCore.App version 2.1.2, but with current settings, version 2.1.0 would be used instead.
Removing the explicitly set --self-contained false from the dotnet publish command seemed to do the trick for us. It defaults to the same, so why it makes a difference, I have no idea.
This was with SDK version 2.1.400.

How to add <frameworkAssembly> into nuget package generated from csproj

I'm using VS2017 and the new csproj file format for creating nuget packages.
In my csproj file I have the following:
<ItemGroup>
<Reference Include="System.Net" />
</ItemGroup>
Which works fine (TargetFrameworks == net45) when you build it. But when I pack it in nuget package I want the target package to have it as
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Net" targetFramework="net45" />
</frameworkAssemblies>
How can I do that with this new tooling?
This is limitation of the current 1.0.* tooling. In the upcoming versions 1.1.* and 2.0.* versions of the ".NET SDK", this will be done automatically, with all <Reference> elements being added as framework assemblies to the resulting NuGet package (unless they are marked with Pack="false"). These changes will also be part of VS 2017 15.3 (not released yet at the time of writing). Note that i am talking about the tools (dotnet --version with SDK installed) version, not the .NET Core runtime versions.
There is a way to use the current preview packages of the pack targets, overriding the ones provided by the SDK - note that this is quite a hacky way and should be removed once you use the new 1.1 or 2.0 tooling.
<Project>
<PropertyGroup>
<NuGetBuildTasksPackTargets>junk-value-to-avoid-conflicts</NuGetBuildTasksPackTargets>
</PropertyGroup>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<!-- All your project's other content here -->
<ItemGroup>
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="4.3.0-preview1-4045" PrivateAssets="All" />
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
Also see the related GitHub issue on the NuGet repo where the information for this workaround originated from.