In the new ASP.NET 5 projects, there are multiple ways / places to control the .NET versions:
In global.json
In Project -> Properties, Application tab, Solution DNX SDK Version (this is the same as the global.json)
In Project -> Properties, Debug tab, Use Specific Runtime
In Package Manager Console, using dnvm list
In a normal console in the application root, using dnvm list
Which of these are the same (apart from the first two) and what do they all do?
The dnx in global.json is only used by VS. No one else uses it and if you run the application outside of VS, there is no guarantee that it'll use that version.
The dnx used to run a particular application is set in two ways:
Either pass the full path to a particular dnx. E.g: C:\dnx\dnx.exe . run
The dnx on the PATH resolved according to your OS' PATH resolution (we don't control that).
When you run dnvm use <version>, that particular version is added to the path and it will be used by that particular process and it's child processes. If you run dnvm use -p <version>, that version of dnx is added to the user's PATH in addition to the process' PATH.
For VS, if no version is specified in global.json by default it uses the dnx under the default alias. The default alias is updated when you run dnvm upgrade or dnvm use -p
Related
I have this situation:
I have a Class library with a target framework set to net6.0-windows
<TargetFramework>net6.0-windows</TargetFramework>
And then I have added a new CLI application which I want to build, pack and install as a global CLI app, which has:
<TargetFramework>net6.0</TargetFramework>
Normally I would change the class library to net6.0, but when I do it - the build says that -windows parameter is mandatory for this kind of project. On top of that, there are other projects in net6.0-windows that need to be set as they are.
I have tried to switch CLI to net6.0-windows, but 'dotnet pack' says - that -windows is not supported.
I also tried to use multi-platform target:
<TargetFrameworks>net6.0;net6.0-windows</TargetFrameworks>
But then dotnet pack says:
C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.PackTool.targets(95,5): error NETSDK1146: PackAsTool does not support TargetPlatformIdentifier being set. For example, TargetFramework cannot be net5.0-windows, only net5.0. PackAsTool also does not support UseWPF or UseWindowsForms when targeting .NET 5 and higher.
Any solution how to access classes from DLL - within my CLI? Is this even the correct approach?
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
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.
I have a solution with many projects. Some target frameworknetcoreapp2.1, some other target framework netstandard2.0 and one project has a double target framework
<TargetFrameworks>netstandard2.0;net471</TargetFrameworks>
I'd want to have a artifact for win10 with a single command:
dotnet publish MySolution.sln -c Release -o "targetFolder" -r win10-x64
With this command I have this error while building the project with double target framework. Here's the errors:
C:\Program Files\dotnet\sdk\2.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CrossTargeting.targets(31,5) error : The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application.
The error is clear. At the end I find that dll compiled in the output directory and it seems like it is a netstandard2.0 dll because my application still works.
I don't like dirty things so, how can I solve my problem?
I would avoid to call N times the "dotnet publish" command if possible.
Don't use dotnet publish with the same output directory on a solution. Especially not with the "-r" argument.
It is dangerous because:
libraries don't have the right trimming behaviour for netstandard facade packages
libraries may have odd behaviour when publishing with "-r", especially for netstandard<2.0 dependencies. (they'd end up copying the .NET Core 1.0/1.1 implementation(!) assemblies)
you may end up with different NuGet dependencies in the output (transitive dependencies)
Copy-to-output/publish-directory items may end up overwriting each other, it may even lead to build failures
Call it individually for all application (console app, web app) projects or create an MSBuild file that publishes these applications.
I'm trying to get an old project to run on the new .NET VM, I've gotten through a few obstacles at this point. For a while I couldn't get DNVM to recognize my project as a .NET project, until I added a couple missing files from a sample project, and used dnvm . kestrel instead of dnvm . web and then I got back about 80mb worth of C# errors...
So I went from not being recognized as a project, to being recognized as a shitty one :/
Anybody beat this level yet? Thank you in advance.
Two questions for you
When you say that you tried dnvm . kestrel, do you mean that you tried dnx . kestrel?
Did you run dnu restore to download dependencies before running dnu . kestrel?
Three command line programs
There are three command line programs that you will use to run a .NET 5 app, and it's easy to confuse them. dnvm is the version manager, dnu is the utility, and dnx is the runtime. It's the runtime not the version manager that you use from your project's root folder to start the kestrel web server.
Startup up an app
Here's the very short version of how to start up a .NET 5 app. After using dnvm to install .NET 5, and after creating a project (and optionally a solution,) you need to use both dnu and dnx in this sequence.
From your solution's folder, run dnu restore. This will download your project's dependencies. If you have only a project and no solution, run this from your project's folder instead.
From your project's folder, run dnx . kestrel to run the web application in the browser.
It sounds like you did number (2) without having first done number (1).
Let me know whether you're able to reach the next level. Also, have you read these articles?
http://docs.asp.net/en/latest/getting-started/installing-on-mac.html
http://docs.asp.net/en/latest/tutorials/your-first-mac-aspnet.html