Migrating to .NET6: Microsoft.NETCore.App.Host.win-x64 not found on TC machine - migration

Background
I want to migrate my repository form .NET5 to .NET6. As there are many projects, the plan is to do it in multiple steps. So it's an intended intermediate step to have some of the projects targeting .NET5 while some other set to .NET6.
I use a personal NuGet feed and the official nuget.org is disabled.
As the first step, I updated global.json
{
"sdk": {
"version": "6.0.201",
"rollForward": "disable"
}
}
which previously used to target version 5.0.201.
I made sure 6.0.201 is installed on my machine by using dotnet --list-sdks
╰─ dotnet --list-sdks
5.0.102 [C:\Program Files\dotnet\sdk]
5.0.201 [C:\Program Files\dotnet\sdk]
6.0.201 [C:\Program Files\dotnet\sdk]
6.0.300 [C:\Program Files\dotnet\sdk]
Then I chose a subset of the projects contained in the repository and changed
<TargetFramework>net5.0-windows</TargetFramework>
to
<TargetFramework>net6.0-windows</TargetFramework>
Everything compiles without a problem. Not even a single warning.
However, Team City machine can't build the repo. I'm getting the following error for all the net5.0 projects (so: the not migrated ones)
NU1101: Unable to find package Microsoft.NETCore.App.Host.win-x64. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, MyLocalNuGetCache
I've searched through my machine, but it doesn't contain the package Microsoft.NETCore.App.Host.win-x64. Despite this fact everything builds nicely.
Also, running dotnet --list-sdks on my TC machine proves that 6.0.201 is installed:
╰─ dotnet --list-sdks
5.0.102 [C:\Program Files\dotnet\sdk]
5.0.201 [C:\Program Files\dotnet\sdk]
6.0.201 [C:\Program Files\dotnet\sdk]
Questions
What is Microsoft.NETCore.App.Host.win-x64 needed for and how can I find it on my machine?
What's the best starting point for an investigation to see why doesn't my repo build on the TC machine?

After a few days of debugging this I've gone down to the root of the problem.
To get explanation about the Microsoft.NETCore.App.Host.win-x64 package see my other post.
As there's no way to specify multiple versions of SDKs in global.json, I wrongfully assumed that SDK 6.0.201 contains also a set of system libraries for .NET5. My not-yet-migrated projects started complaining at missing 5.0.15 packages (e.g. EF Core), so I downloaded them and placed in my personal feed.
The reason for MSBuild to pick up 5.0.15 was that that was the latest .NET SDK installed on my machine.
However, the corresponding .NET SDK (in this case: 5.0.406) was not installed on my TC machine.
That's a quick summary.
I'm going to need both .NET6 and .NET5 apps in my repo - at least for some time. The fact that I can't pin SDK version for both targets in global.json is very misleading. It's already caused a lot of problems and I expect more dragons to show up in the future.

Related

You must install or update .NET to run this application

I have a WebAPI project and I do a post-build process that calls "swagger.exe", which is a tool provided by NuGet Package. To install globally it, I used the following command:
dotnet tool install -g --version 5.3.1 Swashbuckle.AspNetCore.Cli
The problem is: My CI process was working fine yesterday. Today it doesn't work anymore.
I narrowed down the problem to the swagger executable... Just by calling it, without any parameters, it returns the following message:
You must install or update .NET to run this application.
App: C:\Users\DRibeiro\.dotnet\tools\swagger.exe
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '3.1.27' (x64)
.NET location: C:\Program Files\dotnet\
The following frameworks were found:
3.1.21 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
3.1.26 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.17 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Notice that I have the Runtime 3.1.26 installed on my Windows.
Notice, also, that the Swashbuckle.AspNetCore.Cli version 5.3.1 was released in 2020! More than 2 years ago!
So, the question is: Why this Package from 2020 requires a .NET Runtime released 2 weeks ago? Why can't it use one of the other Runtimes that I already have (and was working fine yesterday) ?
I know that I could just install the newer version and the problem would be solved... Just want to keep my CI's running smoothly without having to fix it every time a new Runtime version is released.
It turns out that our Automatic Software Distribution system was not doing it's job correctly and sent to our CI machines the incorrect files for the .NET Runtimes. Probably some human error of the network admin.
I disconnected this particular CI machine from the system and reinstalled the Runtime, and everything worked fine.

Issue Deploying .NET Core WebAPI Project

Hosting company says they have .Net Core 2.2.1 Runtime installed.
I tried to publish project using Framework Dependent Deployment and got error 500. More specifically:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.2.0' 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:
https://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.10 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Contacted hosting company, and they said they don't have Microsoft.AspNetCore.App installed, only Microsoft.NetCore.App. Which I honestly don't really understand.
My question is... I have a WebAPI project, simple thing. How can I deploy to this server?? If they don't have AspNetCore installed, can I provide it? Like most people, I'm new to core... just want to publish this project, it seems like an impossible task.
I did try Self-Contained deployment (they said they don't support it), but got the 500 error.
Here's what they have installed:
==============================
.NET Core SDKs installed:
No SDKs were found.
.NET Core runtimes installed:
Microsoft.NETCore.App 1.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
==============================
Ideas anyone? Thanks.

How to update AspNetCore from 2.2.0 to 2.2.2

tldnr: How do I upgrade Microsoft.AspNetCore.App from 2.2.0 to 2.2.2? It's disabled in the package manager UI.
When I created a testproject I realized that Microsoft.AspNetCore.App was version 2.2.2 (newest version) whereas in my main Api project it was 2.2.0.
I could not update it due to
Implicitly referenced by an SDK. To update the package, update the SDK
to which it belongs
I do have SDK 2.2.104 installed, which should contain 2.2.2 (I love how straight forward Microsoft is with its version numbers)
C:\Users\matthias>dotnet --list-sdks
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
2.2.104 [C:\Program Files\dotnet\sdk]
What's the correct way of updating this all to 2.2.2? I could set the version number for the package in the csproj and it seems to work just fine, but I guess that's not the clean way to go. Why would the UI disable it then.
Project file is from the default template.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
Source: https://github.com/matthiaslischka/netcore222updateissue
UPDATE:
I have now added RuntimeFrameworkVersion 2.2.2 to the csproj like ESG suggested and now I get this strange view:
I've inspected the compiled DLLs with ILSpy and it seems to still be 2.2.0.0
I posted this in response to Andy's GitHub bug, but re-posting it here for further reach:
If you are using .NET Core, the only thing you need to do to update to the patch is install the latest patched runtime on the machine running the app (i.e. your servers, dev boxes, etc.).
.NET Core applications automatically roll forward to the highest patch version associated with the major/minor pair you target. This behavior can be disabled using a setting in [appname].runtimeconfig.json but we strongly recommend you keep it to ensure you always run on the most up-to-date runtime (with all released security fixes).
While we do recommend you run on the latest patch, we recommend you do not update your app to target later patch versions as your app will fail to start if that patch doesn't exist on the target machine. Patches shouldn't be introducing APIs that you need to update to depend upon so there's no need to update the package reference.
Since you have the 2.2.2 .Net core SDK, you force the version of ASP.Net by specifying the RuntimeFrameworkVersion in your csproj.
<PropertyGroup>
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
</PropertyGroup>
I had similar issue with 2.2.8, installing the x86 version of the SDK cinched it. Seems unit tests are 32-bit processes?

ASP.NET Core: A compatible SDK version for global.json version 2.1.400 was not found

I've got an ASP.NET Core project in my solution, targeting .NET Core 2.1. I've added a global.json file at the solution level:
{
"sdk": {
"version": "2.1.400"
}
}
On the Team City agent, I've installed MSBuild Tools 2017 (15.8.1), including .NET Core Build Tools.
From the command line I can see SDK 2.1.400 is installed on the agent:
>dotnet --list-sdks
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
However, building the solution fails on Team City with the following error:
dashboard.csproj : error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
Dashboard.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
A compatible SDK version for global.json version: [2.1.400] from [X:\agent-1\sandbox1\global.json] was not found
Any idea why it wouldn't find SDK 2.1.400 when building with MSBuild given it's present in the SDK list?
I finally worked out that dotnet was not recognised as a command when running on Team City (despite dotnet being recognised as a command from the prompt, under the same Windows account).
The solution for me was to update the PATH environment variable using Team City parameters:
Name: env.PATH
Kind: Environment Variable
Value: C:\Program Files\dotnet;%env.PATH%
It now works as expected.
Verify that the PATH environment variable points to the location where the SDK is installed (C:\Program Files\dotnet\ for 64-bit/x64 or C:\Program Files (x86)\dotnet\ for 32-bit/x86). The SDK installer normally sets the PATH. Always install the same bitness SDKs and runtimes on the same machine.

Visual Studio Team Services - Specific .NET core version [duplicate]

I recently installed VS 2017 RC and then automatically my dotnet version pointed to 1.0.0-preview4-004233. Due to that whenever I create a new project using command dotnet new -t Console I cannot see project.json though I see .csproj file.
When I check dotnet versions available on my machine at - C:\Program Files\dotnet\sdk I see multiple versions available.
Is there any way to switch dotnet core back to an earlier version - 1.0.0-preview2-003133 from 1.0.0-preview4-004233 without uninstalling.
You can do this with a global.json file in the root of your project:
Verify the list of SDKs on your machine:
dotnet --list-sdks
You'll see a list like this.
2.1.100 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
[...lines omitted...]
2.1.601 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
3.0.100-preview3-010431 [C:\Program Files\dotnet\sdk]
Create a folder to be the root of your project, where you are going to run dotnet new.
In that folder, run this command: dotnet new globaljson
The result will look something like this:
{
"sdk": {
"version": "3.0.100-preview3-010431"
}
}
In version, replace the 3.0.100-preview3-010431 with the version you prefer from the --list-sdks list. For example:
{
"sdk": {
"version": "2.2.101"
}
}
Run dotnet --version to verify. You should see:
2.2.101
Run the appropriate dotnet new commands to create your project.
Dotnet usually uses the latest SDK version, unless it finds a global.json file that tells it to do otherwise.
The explanation by microsoft
dotnet looks for the file in the working directory (not necessarily the project or solution directory), and if it can't find one it starts searching upwards from there.
documentation
An easy way to create a global.json file would be to run dotnet new globaljson --sdk-version 1.0.0-preview2-003133 in the directory of your project.
create a global.json from the cli
When we install each dotnet core SDK on OS, the each project can use SDKs version separately. Because the SDK have global installation. We can configuration each project settings by create global.json via this command:
dotnet new globaljson
and finally selected the correct version.
The process for selecting an SDK version is:
dotnet searches for a global.json file iteratively reverse-navigating
the path upward from the current working directory.
dotnet uses the SDK specified in the first global.json found.
dotnet uses the latest installed SDK if no global.json is found.
References:
https://learn.microsoft.com/en-us/dotnet/core/tools/global-json?tabs=netcore3x#globaljson-and-the-net-core-cli
Step-by-Step:
https://stackoverflow.com/a/42078060/14557383
If you want to create a new project using a specific version you can go to this directory 'C:\Program Files\dotnet\sdk' then add an underscore to newer version (all of them) of dotnet that you don't want (only the newer ones is enough) then create your project.
You can check in global.json
Run the command
dotnet --list-sdks
You will see the results
2.2.110 [C:\Program Files\dotnet\sdk]
5.0.103 [C:\Program Files\dotnet\sdk]