Why can't Visual Studio 2017 find installed .NET Core SDKs? - visual-studio

I have a simple project which builds with "dotnet build" and with msbuild from the Visual Studio 2019 Developer prompt, but not from the Visual Studio 2017 prompt or IDE. I would like to understand how msbuild 15 finds the installed SDKs and why they are not up to date, while msbuild 16 in VS 2019 works ok.
It appears that the .NET Core SDKs are not registered with msbuild 15 but I don't know how that registration occurs. I have tried reinstalling the SDK, installing different versions of the SDK, but no luck so far.
Unfortunately just switching to 2019 is difficult because what I really want is to compile a large code base with a build script which assumes 2017 - this is a cut-down repro.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
Compiling from VS2017 developer prompt:
msbuild foo.csproj /nologo
Build started 5/20/2019 7:22:06 AM.
Project "C:\Users\edwin\Source\Repos\foo\foo.csproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrame
workInference.targets(112,5): error : The current .NET SDK does not support targeting .NET Core 2.0. Either target .NET Cor
e 1.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.0. [C:\Users\edwin\Source\Repos\foo\foo.csproj]
Done Building Project "C:\Users\edwin\Source\Repos\foo\foo.csproj" (default targets) -- FAILED.
Compiling in same window with "dotnet build" succeeds, as does "msbuild foo.csproj" in the 2019 developer prompt (which uses msbuild 16).
dotnet --info shows
.NET Core SDK (reflecting any global.json):
Version: 2.2.204
Commit: 8757db13ec
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.204\
Host (useful for support):
Version: 2.2.5
Commit: 0a3c9209c0
.NET Core SDKs installed:
1.0.3 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
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.604 [C:\Program Files\dotnet\sdk]
2.2.204 [C:\Program Files\dotnet\sdk]

I experienced this issue 4 days ago when I was using Visual Studio 2017. And I spent all the days to solve it. After searching, on internet,I realised that it was a versioning issue.
verytime, I tried to create a new project I had this message:
The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
So, I decided to delete all the .Net Core SDK versions and installed the compatible one as indicated on the download Page. See the image below.
[
After installing it, everything started working fine.

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

ACR.UserDialogs Splat - Could not be resolved as it was built against Version=v5.0

I'm not able to build my project When I upgraded my version of Visual Studio 2019 to the latest.
I'm using Splat 2.0.0 as I am user ACR.UserDialogs 6.5.1 as part of a shared project.
I got the following error message:
.nuget/packages/splat/2.0.0/lib/netstandard1.1/Splat.dll" could not be resolved because it was built against the ".NETPortable,Version=v5.0" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.5,Profile=Profile111".
My installed packages:
Xamarin.Mac Version: 5.10.0.153 (Visual Studio Community)
Xamarin.iOS Version: 12.10.0.153 (Visual Studio Community)
Xamarin Designer Version: 16.1.0.464
Xamarin.Android
Version: 9.3.0.22 (Visual Studio Community)
It's related to the Mono Framework version that this particular version of VS is forcing.
Please downgrade to 8.3.11 and install the minimum required version of mono for that and it will work.
Here's the link to VS:
https://download.visualstudio.microsoft.com/download/pr/be7eb138-bef6-460b-90c6-dacd3de18266/18dac98baf9b79fbba45016f59c0e0b0/visualstudioformac-8.3.11.1.dmg
and here's the link to mono:
http://download.mono-project.com/archive/6.4.0/macos-10-universal/MonoFramework-MDK-6.4.0.194.macos10.xamarin.universal.pkg

The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found

I am using Visual Studio 2019 Version 16.3.7. I assume it is the latest update.
When I try to compile a basic .NET Core 2.2 console application:
...I get the following error:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
- The following frameworks were found:
1.0.1 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.11 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
3.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The .NET Core frameworks can be found at:
- https://aka.ms/dotnet-download .
My understanding is that .NET Core 3.0 is backward compatible. Why Visual Studio installer installed all versions of .NET Core except 2.2?
How do I solve this problem?
For whatever reason, .NET Core 2.2 is not installed by the ".NET Core cross-platform development" workload.
Open up the Visual Studio installer then go to the "Individual components" tab and you can install it from there:
In my case was missing x86 .NET Core 2.2.x Platform SDK (Visual Studio .NET 16.4 + .NET Core 3.1 SDK ; xUnit Test Project).
You can try this:
Exist directory 2.2.x in: C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App ?
When no, try Download latest 2.2.x SDK for x86 platform from this URL: https://dotnet.microsoft.com/download/dotnet-core/2.2
Install and try ...
For more info about installed SDK and Runtime you can use command: dotnet --info
For those trying to deploy a file to a non-developer machine and you see this error, use the Project -> Publish option with a Folder Profile and update the settings to be "Deployment mode: Self-contained". Then "Publish" it.
This will embed the runtime into the .exe, making it much larger, but also simple to "just work" on a client machine.
You can install x86 .NET Core 2.2.x Platform SDK as #Martin said.
If you do not need x86 version like me, you can also set
<PlatformTarget>AnyCPU</PlatformTarget>
to
<PlatformTarget>x64</PlatformTarget>
in both main project and test project 's .csproj file
to avoid this problem.
Two options are to run the Visual Studio Update application to see if any missing requirements will be installed for you or to install the net core 2.2 SDK manually from https://dotnet.microsoft.com/download/dotnet-core/2.2 (or https://aka.ms/dotnet-download as mentioned in the error message).
.NET Core 2.2.0 is not supported anymore.
Waiting for the .NET 5

New .NET Core project (2.2) won't compile

I just created a new .NET Core 2.2 project with Visual Studio 2019 Community (Version 16.1.6).
Although as a surprise I could not compile the basic project it created.
I see all kinds of errors as it can be seen on this image:
Running the dotnet --list-sdks command in cmd results in:
1.1.14 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.604 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.701 [C:\Program Files\dotnet\sdk]
2.2.203 [C:\Program Files\dotnet\sdk]
so I have these SDKs installed.
Maybe my SDK installations somehow became corrupted?
When I tried NuGet restore for the solution, this is the output:
All packages are already installed and there is nothing to restore.
Time Elapsed: 00:00:00.2025637
========== Finished ==========
Error occurred while restoring NuGet packages: The local source 'D:\Microsoft\Xamarin\NuGet\' doesn't exist.
I can't recall correctly, but maybe I deleted the latter folder, because it seemed irrelevant (I chose a different location for VS install, so why would the installer copy something there? Non-sense.). If that is the problem, how do I fix it?
Also, why does it even need Xamarin? This is not a xamarin project!
Thanks in advance!
NuGet is trying to read from a local source that doesn't exist. Go to Tools\Options and from NuGet Package Manager, remove the local source or change it. Then you should be able to use NuGet again to restore the missing SDKs.
If still not working, and you think you deleted some folders, then I suggest to uninstall VS and install it again correctly. Templates from VS should works fine.
References :
An error occurred while trying to restore packages. Please try again
Unable to find nuget local source error occurred while restoring nuget packages the local source doesn't exist
For Visual Studio 2019 16.1, you need .NET Core 2.2 SDK 2.2.30x, which can be downloaded from https://dotnet.microsoft.com/download/dotnet-core/2.2

Ionic 2.3.2 [CordovaApp.Windows10.jsproj(61,5): error MSB4019]

When I run ionic build windows i get the below error
Building project: D:\app-Name\platforms\windows\CordovaApp.Windows10.jsproj
Configuration : debug
Platform : x64
D:\app-Name\platforms\windows\CordovaApp.Windows10.jsproj(61,5): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Microsoft.VisualStudio..Default.prop" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe: Command failed with exit code 1
My system info [ionic info]
Cordova CLI: 7.0.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.2
Xcode version: Not installed
I have installed Visual Studio community edition 2017 along with specific 2015 and 2017 build tools including the SDK.
Added the min target preferences in config.xml. Even after everything i'm unable to build it.
Please help me to resolve this issue.
It seems that Cordova looks for MSBuild tools version 14 of Visual Studio 2015.
These release notes suggest setting the environment variable MSBUILDDIR to the correct MSBuild directory installed on your system:
Install MSBuild tools 2015: https://www.microsoft.com/en-za/download/details.aspx?id=48159
Set environment variable MSBUILDDIR to C:\Program Files (x86)\MSBuild\14.0\Bin

Resources