Bamboo NuGet Restore command is running older version of SDK - .net-core

I have a .net core 2.2 web app that has been building successfully in Bamboo for several months. Recently someone rebuilt the new Bamboo server (we're on premise, not in cloud) as the first step in a Bamboo upgrade and my build began failing. The error is:
C:\Program Files\dotnet\sdk\2.1.509\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2.
My original post incorrectly asserted that this error was occurring in a Script task running dotnet publish. I realize now that it is actually occurring in the previous task - a Bamboo Command task running NuGet Restore. And I can reproduce the problem at the command line, so it does not appear to be a Bamboo issue.
So, in summary, I have a .NET Core solution with four projects. All four projects target .NET Core 2.2. I have NuGet 5.3.1 installed on my Bamboo build server. I navigate to the solution directory and run
nuget restore
And I first get the following informational message:
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
Followed by four instances of the following error, one per project:
C:\Program Files\dotnet\sdk\2.1.509\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2.
What is causing the nuget restore operation to be working with .NET Core 2.1 instead of 2.2? Is there a problem with the msbuild auto-detection?
I initially found that .net core 2.2 had not been installed on the new server, so I installed it, so both are now installedre. But the error above persists and continues to reference .net core 2.1.

Instead of running nuget restore use dotnet restore.
A cleaner way to set this up would be to configure a dotnet executable as a Command in Bamboo. By doing this you can ensure that you are running the correct executable every time. Additionally you will gain the following benefits:
The command will show what version it is
This scale to other build agents
Adds clarity to the Bamboo task (will show as dotnet 2.2 instead of a script).
Then you can have dedicated tasks for each step (e.g., restore, build, test)

Related

ASP.Net Core WebApi Project creates an empty solution

I am trying to create a ASP.Net Core WebAPI application, i installed every sdk and runtime i was told to.
I then go into Visual Studio and create the Project from the ProjectCreator.
What I end up with is an empty solution and a project in the specified directory that i cannot open, with the error message the Project cannot be opened because it couldnt find a fitting sdk
(btw, creating it with .netCore3.1)
Heres a list of my installed sdks/runtimes:
.NET Core Runtime 2.1
.NET Core Runtime 3.1
.NET Core SDK 3.1.1
.NET Core SDK 3.1.4
.NET Runtime 5.0
.NET SDK 5.0.2
.NET SDK 5.0.3
ASP.NET Core 3.1.17
ASP.NET Core 5.0.8
This is what my solution explorer looks like tho the csproj is correctly placed
Whats seems to be the problem? Too many runtimes/sdk?
Are they overriding each other? Visual Studio cannot choose? I am baffled, this should work :/
[Edit1]
This is the guide I am following: https://learn.microsoft.com/de-de/aspnet/core/tutorials/first-web-api?view=aspnetcore-5.0&tabs=visual-studio
[Edit2]
I found a command that lets you see every sdk and runtime the dotnet/cli can access/see
(dotnet --info)
Looks like dotnet doesnt seem to find an sdk i installed
[Edit3]
I tried to manually install the .net core SDK 3.1 binaries into the C:\ProgramFiles\dotnet folder, but to no avail, dotnet --info still doesnt recognize the SDK
[Edit4]
I got it working, I will post the solution as an answer.
Heres what I did:
I uninstalled my Visual Studio IDE with the Visual Studio Installer
I uninstalled every .NET (Core) SDK and .NET (Core) Runtime
I did a fresh Visual Studio install with only the components i really need
After that I checked the dotnet --info command and there was it, 2 SDKs were installed. When I create the WebAPI Project now, the Solution Explorer has a project and I can finally see all files. This was weird. Thanks everyone tho!

Adomdclient for dotnet core 2.2

I am using the unofficial ADOMD client
https://www.nuget.org/packages/Unofficial.Microsoft.AnalysisServices.AdomdClientNetCore/
It looks fine in my project that target dotnet core 3.1. However, it keeps on returning error when I use it on project that is targeting dotnet core 2.2.
The error received is "The operation was canceled."
Is it unsupported for dotnet core 2.2? Ia there anyway to make it works on dotnet core 2.2?
Since your question was posted, an officially maintained ADOMD.NET (Microsoft.AnalysisServices.AdomdClient) for .NET Core is available in preview on nuget. You can consider using this library instead of the unofficial library.

Where is Microsoft.AspNetCore.Antiforgery library defined in .NET Core 2?

Environment: Ubuntu 16.04
I have written an ASP.NET application that is based on .NET core 1.1. This application works as expected. Today, I just upgraded my server to dotnet-sdk-2.0.0-preview2-006497. After the upgrade, I ran the following commands in my project directory to make sure everything is up to date:
$ dotnet migrate
$ dotnet restore
Now, when I run my application and try to navigate to my login page, I get an error "Cannot find compilation library location for package Microsoft.AspNetCore.Antiforgery."
Wondering how I can fix this. Regards.
As currently dotnet migrate only migrates a Preview 2 .NET Core project to a .NET Core SDK 1.0 project, you have to manually update your app to targeted to .NET Core 2.0 preview and Microsoft.AspNetCore.Antiforgery dependency in csproj to be 2.0.0-preview2-final (and the same for other dependencies).

How to run ASP.NET Core Web application on Linux?

I have an ASP.NET Web application that was successfully running on Linux with the help of dnx-mono NuGet package. I used to publish it by using dnx publish tool and run it with the command:
/opt/dnx-mono.1.0.0-rc1-update1/bin/dnx --appbase /path/to/json Microsoft.Dnx.ApplicationHost kestrel
Since dnx is obsolete, I want to get rid of it and migrate to .NET Core, but it does not work anymore on Linux.
Important: I cannot make my application .NET Core app because it uses some libraries (like MySQL.Data) that are still not available for .NET Core. Therefore, I create ASP.NET Core Web Application (notice .NET Framework):
I migrated the whole application and run it successfully on Windows, but my target is Linux. No more dnx publish, no problem - there is dotnet publish which works well and produces binaries. What now? Dnx-mono package does not have a "dotnet-something" successor, and using dotnet command with published binaries produced errors that I was not able to resolve (The library 'libhostpolicy.so' required to execute the application was not found), but I don't think that I should even use dotnet command with standalone binaries. Googling didn't help as most tutorials are focused around ASP.NET Web applications for .NET Core, not for .NET Framework. Version of Linux is Debian 8, dotnet command was obtained by following this guide. Any clue?
You cannot run an application on Linux that targets the full .Net Framework, it has to be Core only.

Removing complete ASP.net 5 RC1 environment before moving to DOTNET Core RC2 from OSX

Recently, there is RC2 release for donet core tools. Previously, I have been using RC1 for asp.net 5. It was installed using .pkg file provided at get.asp.net.
Now, I am planning to try out dotnet core release. The instructions provided at get.asp.net ask to unistall the previous versions of dotnet core using this script.
I have 2 questions here.
Is it required to remove the RC1 release (dnvm,dnx and dnu etc) before installing dotnet core?
If it is required to uninstall, what is preferred way of doing it (something like above script) without damaging the required/shared files?
Ad 1. Yes. As you can read in ASP.NET Core installation guide:
Before you start
Remove all previous versions of .NET Core from your system.
Ad 2. In my case I just use Add/Remove programs, but it's Windows.
I have no experience with Linux, but you do not need DNX any more so no worries about required files - after a while you will install new RC2 with all required files ;)

Resources