What does the "reflecting any global.json" message mean in dotnet info output? - .net-core

This is what I see when I do a dotnet --info on my Windows 10 system:
It says:
.NET Core SDK (reflecting any global.json)
I honestly don't understand what "reflecting any global.json" would mean. Before posting this question, I did several searches and could not find any explanation.

When one runs the dotnet command, and multiple SDK version are installed on the system, the exact version used can be set in a global.json.
So I believe it means that the version printed in console is what may come from global.json, if there is such a file.
You can try this by creating global.json in the current directory via dotnet new globaljson --sdk-version 2.1.600 (referring to versions available on your machine). When you use dotnet --info (or any other dotnet <verb> command), the CLI in version 2.1.600 will be used.
global.json file is searched for in the current directory and upwards the hierarchy, so I think it's just saying "watch out, the version you see may be different than you expected because of this global.json somewhere".
To confirm it's nothing extra you can even take a look at .NET Core CLI sources - here and here. There are no special conditions why "reflecting any global.json" is printed.

Related

"dotnet" command does nothing

I'm trying to install a global package through dotnet cli but the command dotnet does nothing. I don't get an error message that says the command is not found etc. but it also doesn't run.
Between each line, cursor inside the powershell (or command prompt) turns into Working In Background ( ) mode but after just a few seconds, it just gets into the new line without doing anything. During these few seconds, if I move the cursor outside the prompt, it goes back to regular mode. So it's doing something I guess.
What is happening here, and how can I solve this issue?
What have I already tried:
1-) Since my network is behind a proxy, I've added the proxy credentials through NPM configuration commands. (as can be seen here)
(I also set the strict-ssl to false).
2-) Since it didn't do anything, I also used this method and edited the global nuget.config file. But didn't solve any problem.
3-) I tried this too, but setting the environment variable MSBuildSDKsPath seems to do nothing about my problem.
My PATH variable has these:
C:\Program Files\dotnet,
%USERPROFILE%\.dotnet\tools
I also downloaded the latest Dotnet 5.0 SDK and installed it, but nothing.
Only command that works with dotnet is the --list-sdks command which shows this result:
I uninstalled all the .NET SDKs and runtimes, I also removed all the installed modules on both VS 2019 and VS 2022 Preview using the Visual Studio Installer, then restarted my computer.
While installing the SDKs and runtimes from Microsoft's website I checked the .NET version using the command line and command dotnet --version after every installation to see when exactly it starts not working. After installing all the SDK's up to .NET 5, there was no issue. And since I did not really need the .NET 6 SDK I didn't specifically download it thinking VS 2022 Preview would automatically install it anyways.
Using Visual Studio Installer, I installed the necessary components for the dotnet development on the VS 2019 and the previously mentioned command was working on point. Then I proceeded to install the necessary components on the VS 2022 Preview but after installing it, the command started to not work. So there it was, the source of the problem. Something about VS 2022 Preview's installment process just corrupts dotnet cli, but I'm not sure if it's just me.
You also need a restart after all the installments or dotnet cli might show some errors.

dotnet build stopped working after VS 2022 upgrade

I upgraded Visual Studio Community to the final release, and it stopped working. Specifically, I could generate a new project, but when I try to load it, it gave me an error
Critical Project 'SdkTest' load failed| [MSB4236] The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. ...\SdkTest.csproj
Even though build and run worked fine
I ran "repair" on VS2022, and it seems to be working now from Visual Studio. However, dotnet --info doesn't show any SDKs; only runtime; and dotnet build or dotnet new give an error:
C:\Code>dotnet new console -o myapp
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'new' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
I even reinstalled .NET 6 and I see it in the list of applications (along with older SDKs). I checked the path, and I see everything that I expect to see:
C:\Program Files (x86)\dotnet\
C:\Program Files\dotnet\
C:\Users\me\.dotnet\tools
I am running Windows 11.
It's known bug in VS2022 installation.
Problem is that dotnet you access is located inside Program Files(x86)/dotnet, but all sdk's are located in Program Files/dotnet. You simply need to edit PATH environment variable so Program Files/dotnet goes before Program Files(x86)/dotnet. If you don't see Program Files(x86)/dotnet in user environment variable (which is likely to happen) then edit system environment variable (located below)
Example with screenshots: https://stackoverflow.com/a/44272417/10339675

dotnet publish results include different set of libraries when run in linux/windows

While configuring some of our gitlab runners - some Windows, others Linux - I noticed something I find curious. The artifacts created by Linux runners include some libraries that are not included in the artifacts created by Windows runners.
The files in question are:
System.Collections.Immutable.dll
System.ComponentModel.Annotations.dll
System.Diagnostics.DiagnosticSource.dll
This happens no matter if a target runtime has been specified or not, e.g.
dotnet publish ./Project/Project.csproj -c Release
will include the three files mentioned above when run under Linux, but not when run under Windows (SDK 3.1.300). The project runs just fine without these.
Can anyone explain what's happening here? I was under the impression the result of a dotnet publish command is always the same regardless of the OS.

No executable found matching command "dotnet-add"

I just did a fresh install of Fedora 25 (followed by an install of dotnet core 1.1) to explore the possibilities of doing some dotnet core development in an linux environment. On attempting to add my first package I received the following error:
No executable found matching command "dotnet-add"
I have seen some similar errors in other SO posts, but nothing that seems to be helping this issue. I attached some images below of the error, dotnet version info, system path, and dotnet location.
Thanks ahead of any tips!
You have installed a version of the dotnet SDK ("CLI" / dotnet-dev package) of the preview2 time, which is still project.json based. This version of the CLI does not contain the dotnet add set of verbs. These were publicly released with the 1.0.0 version. (at the time of writing, the current version of the SDK / CLI is 1.0.4).
Depending on which instructions you followed to install the components, make sure to update to new versions of the SDK / CLI (e.g. microsoft's install instructions for Fedora).
Note that the version of the SDK / CLI is a different one that the version of the runtime(s) on the machine.
Had the same trouble running VS 2017 Version 15.3.5 found a very helpful article
http://thedatafarm.com/data-access/no-executable-found-matching-command-dotnet-ef/
My Basic problem is the tooling is split into two:
One for CLI: Microsoft.EntityFrameworkCore.Tools.DotNet
One for Powershell: Microsoft.EntityFrameworkCore.Tools

How to restore an ASP.NET Core project with Ubuntu

Recently, I created an asp.net core project using Visual Studio Code on Windows and pushed it to GitHub. When I cloned the repo from GitHub and attempted to do a dotnet restore on the project on Ubuntu, an error message stating there was no project.json file was returned. Can anyone point me to a resource that will show me how to properly restore a .net core project from a Linux machine? Thanks!
So it seems like on each of your machines you are running different versions of the .net core SDK.
A big caveat with what you are trying to do. Are you trying to use Project Rider from Jetbrains on Linux? This only works with project.json (As of the time of this post) so be wary of that.
Now there are two ways to do this. If you are wanting the very latest on Linux and don't care about using Rider, then you can go here : https://github.com/dotnet/core/blob/master/release-notes/download-archive.md and download the latest release for both Linux and Windows, install on both and you should be good to go.
If you do care about using Rider or you aren't ready to be strapped in for the wild ride of the latest release. Then you can do the following.
Find what version of the SDK you have on linux by typing into a terminal the following :
dotnet --version
This will spit out what version you have on linux. Go here and download the same version for windows and install it on your windows machine (https://github.com/dotnet/core/blob/master/release-notes/download-archive.md).
Now BEFORE you create a project, create a solution folder and create a file in it called global.json. Inside that put the following :
"sdk": {
"version": "1.0.0-preview2-003131"
}
Where the SDK version matches what you got from your linux terminal. Now create a folder for your project inside the solution folder. Run "dotnet new -t web" or a similar command to create your project. It will inspect the SDK version of the global.json and create a project with the tooling that matches. You should then be able to shift this project around any machine that has the same SDK installed, even if it also has the latest SDK's also.
If you do not create the global.json, it defaults to the latest version (Atleast on Windows).
Read a bit more about it here : http://dotnetcoretutorials.com/2017/02/17/developing-two-versions-net-core-sdk-side-side/

Resources