Visual Studio not recognizing installed Core SDKs - visual-studio

I have three versions of .NET Core installed on my machine:
However, both VS2017 and VS 2019 return the following error when I execute dotnet --version command:
PM> dotnet --version
dotnet : Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
I can create a solution targeting .NET Core but when I create a Console App targeting .NET Core, for example, the Debug button is labeled Attach instead of Start as usual, and Start Debugging and Start Without Debugging commands in the Debug menu are disabled.
What I tried so far:
Added "C:\ProgramFiles\dotnet" to system PATH variable.
Modified VS2019 using VS Installer.
Restarted several times.
I did have several other version of .NET Core but uninstalled them since I had no solutions targeting these versions and wanted to clean up.
I only left 2.2.300 and 3.0.100 and when I used VS Installer to modify VS2019 it added SDK 2.1.700.
Any ideas on how to resolve this issue without completely removing Visual Studio and installing from scratch?

Apparently x86 version(s) of .NET Core SDKs must be installed as well. After installing 3.0.100 x86 dotnet --version command works fine and I can build and debug .NET Core projects...

Related

dotnet build not finding Xamarin

When running dotnet build in my project, I have the following error:
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.Android/My.Company.Toolkit.Platform.Android.csproj(91,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/Android/Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.iOS/My.Company.Toolkit.Platform.iOS.csproj(195,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.
I confirm that /usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets does not exist.
But I don't know how to install it there.
The reference to Xamarin is defined in the csproj like this <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />.
When I build from Visual Studio I have no issues. And if I try to re-install Xamarin, it says it is already installed.
I am on MacOS.
[UPDATE]
I uninstalled everything (Visual Studio, SDKs/Runtime, dotnet, etc).
Installed just Visual Studio 2022 for Mac.
➜ ~ dotnet --info
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480
Runtime Environment:
OS Name: Mac OS X
OS Version: 13.1
OS Platform: Darwin
RID: osx.13-arm64
Base Path: /usr/local/share/dotnet/sdk/7.0.102/
Host:
Version: 7.0.2
Architecture: arm64
Commit: d037e070eb
.NET SDKs installed:
6.0.405 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Now if I try to build the project in the terminal I still have the same error. But if I try to build it from Visual Studio I have a different error.
I have this error in the build output
Target RazorGenerateComponentDeclaration:
/usr/local/share/dotnet/dotnet exec "/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll" generate
-s
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/_Imports.razor
-r
_Imports.razor
-o
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/obj/Debug/netstandard2.1/RazorDeclaration/_Imports.razor.g.cs
-k
component
-p
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web
-t
obj/Debug/netstandard2.1/MyCompany.Toolkit.Platform.Web.RazorComponents.declaration.json
-v
3.0
-c
Default
--root-namespace
MyCompany.Toolkit.Web
--csharp-language-version
8.0
--generate-declaration
The application to execute does not exist: '/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll'
/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets(106,5): error : rzc generate exited with code 129.
Done building target "RazorGenerateComponentDeclaration" in project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.
Done building project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.
Build FAILED.
The tools directory does not exists.
At fisrt, you said:
When I build from Visual Studio I have no issues.
The cause should be when you build from the Visual Studio. The framework your project used is .netstandard 2.0. You can check the project.csproj file and the SDK in the /usr/local/share/dotnet/sdk.
In addition, you can check this case which has the similar error as yours. According to it, if the .net version is not compatible with the xamarin will also get this error. dotnet/sdk/7.0.102 should be the .net 7 which is compatible with the .net maui not the xamarin. So you can't use the dotnet build the project.
You can try to find the right value of the MSBuildExtensionsPath and set it in the android and ios .csproj file according to this case which is about set the project's MSBuildExtensionsPath.
Finally, you can try the solution in this case which has the same error message.
The Xamarin tool chain was built upon Mono, so everything you triggered in VS for Mac is kindly processed by MSBuild for Mono (at Mac terminal you can use msbuild --version to learn more).
dotnet build, however, was designed exclusively for .NET Core based projects, so by default it won't be able to handle Xamarin projects, but only .NET MAUI.
As legacy Xamarin projects are going away soon, you should start to migrate to MAUI as soon as you can,
https://dotnet.microsoft.com/en-us/platform/support/policy/xamarin

Installed .net Framework and it does not appear in Visual Studio

I installed .Net Framework 6.0 from https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk. I rebooted. When I open VS 2019 and try to config a project that version is not in the list.
When I run dotnet from a command prompt I get:

How to exclude a .NET 5.0 project from build depending on the OS

We have a Visual Studio solution with several .NET 5.0 projects, one of which is a Windows Application (TargetFramework is net5.0-windows). It obviously fails to build on Linux and Mac. How can we make it so that it would build or not build, depending on the OS? The scenarios we need to support are:
Building from Visual Studio on Windows.
Building from JetBrains Rider on Windows and Mac.
Building from command line on Windows, Mac and Linux. For command line we currently use dotnet build, as well as dotnet test and dotnet pack which build the solution first.

What determines whether my .net core uses .csproj or project.json

I've got a machine with .NET Core 1.1.0 1.0.0-preview2-1-003182 installed as well as VisualStudio 2017 RC. When I create a project using "dotnet new -t Console" it requires a project.json file. When I create a .NET Core ConsoleApp in Visual Studio 2017 it requires the .csproj for build configuration. What determines this? I'd like to have one or the other, preferably consistent .csproj since project.json is deprecated for future versions as far as I can tell.
VisualStudio 2017 RC won't seem to build a self-contained executable, so I revert to the command line to attempt a "dotnet publish -t win10-x64" whereby I get the error that there is no project.json. So, even if I have my .csproj configured to build an .exe, I can't just build it.
The version of .NET Core Tools is the reason:
.csproj is used starting from .NET Core Tools Preview 3
Note: Visual Studio 2017 RC installs .NET Core Tools Preview 3 (or even Preview 4 now).
project.json is used in previous versions.
If you want to know with version of .NET Core Tools is used then go to root project folder and run next command:
dotnet --info
Possible output:
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
If you have more then one version of .NET Core Tools on your machine, you can directly specify with version should be used for your project by global.json. Create (if not exists) this file in root folder and add "sdk" section. For example for Tools Preview 2:
{
...
"sdk": { "version": "1.0.0-preview2-1-003177" }
}
Also you may use dotnet-migrate command to convert your project.json to .csproj

Visual Studio Hangs After Cordova Run

My Visual Studio Enterprise Hangs after i build and run my Cordova Application. Take note that I have not done anything yet but create the app then run it.
I tried changing my CLI to: 5.3.3 but still gives the same problem.
My current CLI version is 6.1.2
Help

Resources