I've got a .Net Core project from one of my colleague that has been managed by .Net SDK 5 and VS Code. But now I want to manage it in Visual Studio 2019, as it is easier to navigate codes and run/debug project. I could open the project folder, by choosing File/Open/Folder... and select the project folder in VS 2019. But when I try to run it by click run button in the tool bar as below, I get the alert box as below next. I clicked this run button to run project Build failed alert message
And here is the build output.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1183,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v5.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
I tried to solve this project, but I couldn't manage it. What I installed is:
- Microsoft .NET SDK 5.0.400
- Visual Studio 2019 16.0.1
- ASP.NET and Web Tools 2019 - 16.0.12311.10635
- ASP.NET Web Frameworks and Tools 2019 - 16.0.12311.10635
- Other more
And the Api.csproj file is as follows:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HangFire.Core" Version="1.7.*" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.7.*" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.*" />
<PackageReference Include="Dapper" Version="2.0.90" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
<PackageReference Include="StackExchange.Redis" Version="2.2.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.3.3" />
<PackageReference Include="NBitcoin" Version="5.0.55" />
<PackageReference Include="Nethereum.HdWallet" Version="3.8.0" />
<PackageReference Include="Nethereum.Signer" Version="3.8.0" />
<PackageReference Include="Nethereum.Web3" Version="3.8.0" />
<PackageReference Include="NBitcoin.Altcoins" Version="2.0.20" />
<PackageReference Include="Postmark" Version="4.5.0" />
<PackageReference Include="Wangkanai.Detection" Version="3.0.0" />
</ItemGroup>
</Project>
Any can help me solve it? Thanks.
CodePudding user response:
I had similar problem that defied all logic. What I ended up doing, I created a new solution in VS2019 (not sure what kind of project you have, but let's say Web Application). Then just add the code files from VS Code project; add missing libraries - and go ahead.
Note, that when you create new solution you will see what framework you are using. Make sure it is .NET 5 (that will confirm that you have .NET 5 installed - it usually is installed as part of VS2019 install). Obviously, if you can't scaffold / build / run your solution - you have bigger problems.
Also, not that I use the word solution
(.sln file) when you open in VS2019, and project
(.csproj file) is what you create in VS Code. You can still open project in VS2019, but it will prompt you to create and save solution
CodePudding user response:
there could be two issues
- missing SDK, you can check SDK version using
dotnet --version
the output should be 5.0.x
or
try to use following
dotnet --info
it will give you all the SDK information, for me output is
.NET SDK (reflecting any global.json):
Version: 5.0.201
Commit: a09bd5c86c
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.201\
Host (useful for support):
Version: 5.0.4
Commit: f27d337295
.NET SDKs installed:
5.0.201 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
if you don't have .NET 5 SDK, please download it from https://dotnet.microsoft.com/download/dotnet/5.0 and restart your solution.
- you are using an outdated version of the visual studio, please check if any updates are available. for .NET5 you need at least VS 2019 16.8.
CodePudding user response:
I have similar issue, VS 2019 16.0 not support .net core 5
You need to update your visual studio 2019. If you go to property project you find that .net core isn't listed, after the update all work correctly.
CodePudding user response:
You have to update Visual Studio 2019. On download page, you can see minimal version of Visual Studio that supports .NET 5.