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

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

Related

VS Project requires version of .NET that is not used

I just launched a VS project that I launched many times in the past, but suddenly I get an error message that surprises me:
You must install or update .NET to run this application.
App: {PATH TO MY PROJECT}.exe Architecture: x64 Framework:
'Microsoft.NETCore.App', version '2.1.0' (x64) .NET location:
C:\Program Files\dotnet\
The following frameworks were found:
5.0.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
But I updaded my project to .NET 6 already some months ago, so its strange for me that it complains about Microsoft.NETCore.App 2.1.0.
So I was wondering if maybe a NuGet Package that I installed also has any dependency on this old version.
Is there any way how I can traverse my .NET 6 project to find the dependency that still requires 2.1.0?
How can I find out the dependency that might cause this issue in my dependency tree?
What could cause this problem to appear so sudden?

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

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

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.

The WiX Toolset v3.11 (or newer) build tools must be installed to build this project

Just installed Visual Studio 2017 and wix extension and when trying to build a solution which uses Wix I get the following error:
Error The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. Could not find wix.targets at 'C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\'. To download WiX Toolset v3.11 (or newer), see http://wixtoolset.org/releases/ Installer C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\WiX\v3.x\Wix.targets 10
In folder "C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\" I have the following files
2017-11-29 15:12 <DIR> .
2017-11-29 15:12 <DIR> ..
2017-05-01 07:34 293 705 difxapp_x64.wixlib
2017-05-01 07:34 203 950 difxapp_x86.wixlib
2017-02-27 23:52 3 369 LICENSE.TXT
2017-02-27 23:52 4 233 lux.targets
2017-03-28 02:20 9 067 wix.ca.targets
2017-05-01 07:32 1 731 wix.nativeca.targets
2017-03-28 02:20 1 097 wix.targets
2017-02-27 23:52 145 601 wix200x.targets
2017-02-27 23:52 146 067 wix2010.targets
Which includes the file "wix.targets" which Visual Studio reports as missing. What am I doing wrong?
A computer-restart later and its now working. So if someone have the same problem I recommend this after installing WiX. (restarting visual studio was not enough)
To fix this issue you need download and install:
"WiX Toolset build tools" also
NOT just
"WiX Toolset Visual Studio Extension"
from here: https://wixtoolset.org/releases/
Open your csprog project file with notepad and edit this line (in my case I use WiX version 4)
From:
<WixCATargetsPath Condition=" '$(WixCATargetsPath)' == '' ">$(MSBuildExtensionsPath)\WiX Toolset\v4\Wix.CA.targets</WixCATargetsPath>
To:
<WixCATargetsPath Condition=" '$(WixCATargetsPath)' == '' ">C:\Program Files (x86)\WiX Toolset v4.0\SDK\Wix.CA.targets</WixCATargetsPath>
I tried the above solution and wasn't able to resolve the issue even after repeated reinstall and reboots.
I removed the existing setup project and created a new setup project, this solved my issue. Caution, backup your setup project before removing it so you don't loose your work or have to recreate from scratch.
May be a tip to others who might be stuck with the issue even after reinstall and reboots.
I had installed the WiX.Toolset package via NuGet package manager. Latest is 3.9.1208 as of this post, however my installer wanted at least 3.11. I uninstalled the WiX.Toolset package and installed the Wix.Toolset.UnofficialFork package, which is v3.11.2. After a restart of VS, everything worked great.
problem: even though the tool set not present , it was shpwing already installed and not showing in the controlled panel program list as well .
Solution
if you are getting the error "The WiX Toolset v3.11 (or newer) build tools must be installed to build this project" then need to nuget pkg manager and installed it manually , which will resolve this error . it worked for me .

Microsoft.NETCore.APP >= 1.01 could not be resolved on Windows 7

I have installed Microsoft Visual Studio 2015 Enterprise edition update 3 on my Windows 7 machine.I also installed .Net Core packages from this link:
https://www.microsoft.com/net/core#windows
I rebooted the machine after the installation. Now when I try and create a simple web application it throws errors related to project.json. The following are the errors thrown in Visual Studio 2015:
Severity Code Description Project File Line Suppression State
Error NU1001 The dependency Microsoft.NETCore.App >= 1.0.1 could not be resolved. WebApplication14 C:\WebApplication14\src\WebApplication14\project.json 3
I haves similar errors to all the dependencies in the project.json file. I tried many options mentioned online but it did not resolve the issue. I also tried uninstalling and installing .Net core and no luck. Could you let me know how I could fix this issue.
I was able to resolve the issue. I tried uninstalling and installing .Net core and it did not work. The problem was with the NuGet Cache. The cache is stored in different location and we need to clear it which will help the packages to be restored. Follow these steps:
Go to the directory where nuget.exe has been installed and run these commands:
1) nuget locals all -list
2) nuget locals all -clear
When you run the second command you will get a warning we can just ignore that.After executing these two commands restart Visual Studio and open the project solution and it should work.

Resources