dotnet restore with update in the new csproj/msbuild-based projects? - nuget

How do I actually update the new csproj-based project's Nuget packages to the latest ones when using Visual Studio Code?
This is what I have within the .csproj file:
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.0" />
If I do dotnet restore it will only install the specified package versions.
There is no dotnet restore update or dotnet nuget update option available.
All of the above referenced Microsoft.AspNetCore.* packages have newer versions (1.1.0).
I would like to update the packages and have the references updated automatically in the same way we do this in Visual Studio.

Currently, VS Code does not have a built-in Nuget Manager tool. The only possible way is to edit .csproj file manually and update versions.
If regarding VS Code extensions, there is a Net Core Project Manager extension, that works pretty well.

Related

Install .NET Standard version of a multi-target Nuget from a .NET 4.6.2 application?

Is it possible from a .NET 4.6.2 application to prefer .NET Standard version installation of a multi-target Nuget?
I have a .NET 4.6.2 application which is using a Nuget package built for both .NETFramework 4.6.2 and .NETStandard 2.0
When looking into the .csproj project file I can see this:
<Reference Include="CompanyAcme.TheNugetPackage.Client, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\TheNugetPackage.Client.2.1.4\lib\net462\CompanyAcme.TheNugetPackage.Client.dll</HintPath>
</Reference>
Which makes me think that my .NET 4.6.2 application is using the .NET 4.6.2 version of the Nuget package.
You can do it with this filthy hack, but I'd certainly think twice before doing it
<PackageReference Include="Prism.Core" ExcludeAssets="Compile" GeneratePathProperty="true"> <Version>7.1.0.431</Version> </PackageReference>
<Reference Include="Prism"> <HintPath>$(PkgPrism_Core)lib\netstandard2.0\Prism.dll</HintPath> </Reference>
From https://duanenewman.net/blog/post/a-better-way-to-override-references-with-packagereference/

EF Core cannot install the Initial Migrations

These are the packages I have:
And this is my global.json file:
{
"sdk": {
"version": "3.1.101"
}
}
And this is my project file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
</ItemGroup>
</Project>
Now I am trying to run this command but I get an error. What am I missing?
dotnet ef migrations add Initial
Error I get:
A compatible installed .NET Core SDK for global.json version [3.1.101] from [C:\MyRepoz\SportsSln\SportsStore\global.json] was not found
Install the [3.1.101] .NET Core SDK or update [C:\MyRepoz\SportsSln\SportsStore\global.json] with an installed .NET Core SDK:
1.1.14 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.508 [C:\Program Files\dotnet\sdk]
2.1.512 [C:\Program Files\dotnet\sdk]
2.1.801 [C:\Program Files\dotnet\sdk]
2.2.401 [C:\Program Files\dotnet\sdk]
3.1.301 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]
OK the problem was that it specifically needs version 3.1.1 of .NET Core SDK.
So I went to their website and downloaded it and installed it.
Website is this: https://dotnet.microsoft.com/download/dotnet-core/3.1
Looks like dotnet is not recognised (you can verify it by typing dotnet --list-sdks, which should produce same error).
The solution should be to add env variable to PATH which points to the directory that contains SDKs. On Windows x64, this should be C:\Program Files\dotnet.
Also verify that C:\Program Files\dotnet\sdk\3.1.101 actually exists.

Package Microsoft.EntityFrameworkCore.Sqlite 5.0.0-rc.1.20451.13 is not compatible with net50 (.NETFramework,Version=v5.0) / win7-x86

I want to update my packages but I got some errors like this:
The error is:
Error NU1202 Package Microsoft.EntityFrameworkCore.Sqlite
5.0.0-rc.1.20451.13 is not compatible with net50 (.NETFramework,Version=v5.0) / win7-x86. Package
Microsoft.EntityFrameworkCore.Sqlite 5.0.0-rc.1.20451.13 supports:
netstandard2.1 (.NETStandard,Version=v2.1) API
E:...\API\API.csproj 1
API.csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
<PackageReference Include="CloudinaryDotNet" Version="1.11.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0-preview.8.20414.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-preview.8.20407.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0-preview.8.20407.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0-preview8" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.7.1" />
</ItemGroup>
</Project>
C:\WINDOWS\system32>dotnet --info .NET SDK (reflecting any
global.json):
Version: 5.0.100-rc.1.20452.10
Commit: 473d1b592e
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program
Files\dotnet\sdk\5.0.100-rc.1.20452.10\
How can I solve this problem?
I had the same issue:
I updated my Visual Studio program from version 16.7 to 16.8 and now, problem solved!
I checked update manually
This solution is written in the comments of this question but I wanted to make it an answer to help others like me
You have to upgrade your nuget installer to latest version.
https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite/
https://www.nuget.org/downloads
If you are using Azure Devops, you can add a task step into your pipeline.
- task: UseDotNet#2
inputs:
packageType: sdk
version: 5.0.x
- task: NuGetToolInstaller#1
inputs:
versionSpec: ''
checkLatest: true
To develop any ASP.NET Core 5.0 app, you need Visual Studio 2019 version 16.8 or later, with the ASP.NET and web development workload installed.
https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net50
https://learn.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/create-project
I had a global.json file in my project. After removing it problem was fixed because it mentioned a .net core 3.1 sdk.
Open .csproj file in notepad and change the target version from 3.1 to 2.1
From
<TargetFramework>netstandard5.0</TargetFramework>
To
<TargetFramework>netstandard2.1</TargetFramework>
Save file and close. Clean Solution then rebuild the solution.

Microsoft.AspNetCore.App vs Microsoft.NETCore.App publishing problem

I have a .NET core 2.2 application which I'm trying to publish to my web hosting but I'm getting a "500 - Internal Server Error" as a result.
I contacted support and they located the problem as being the following:
We enabled detailed error for your website and it is showing "Handler >"aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list". It seems that you are using Microsoft.AspNetCore.App 2.2.1 for your website
application and this version is not installed on the server. Due to this website is not working.
On the server Microsoft.NETCore.App 2.2.1 is installed. So we would suggest you to re-deploy the application using .NetCore 2.2.1 and again check the website.
We only support .Net core runtimes installed on our shared hosting server. Re-deploy your application using the correct version to avoid any further issues. Please note that we do not support SCD (Self Contain Deployed application) on our shared server. We do support FDD (Framework Dependent Deployed application) only.
If I do a "dotnet --info" I can see that both .NETCore.App and AspNetCore.App are installed on my machine.
.NET Core SDKs installed:
2.2.103 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.1 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program > Files\dotnet\shared\Microsoft.NETCore.App]
My .csproj is referencing Microsoft.AspNetCore.App but it seems I cannot change this to Microsoft.NETCore.App.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.1"/>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1"/>
</ItemGroup>
</Project>
Is there any way I can deploy this app to use Microsoft.NETCore.App so it works on the server?

Microsoft.EntityFrameworkCore.Tools.DotNet v2.0.1

Currently Microsoft.EntityFrameworkCore.Tools.DotNet V2.0.1 is showing a dependency of .NetCoreApp Version = 2.0
Any reason why that isnt version >=2.0 ?
Any idea when support for the more recent versions of
.NetCore SDK will be available
EDIT: Added screenshot
See dependency listed as .NetCoreApp = v2.0 and not .NetStandard = V2.0 or >= CoreApp V2.0 for similar packages.
edit2:
I ran the following new Project tests:
i still think there is an issue here.
I have .netcore sdk 2.1.4 installed
I started with brand new solution in VS2017 15.5.5
I create a new core project
netcoreapp2.0
and a new standard project
netstandard2.0
These packages
o Microsoft.EntityFrameworkCore.tools v2.0.1
o Microsoft.EntityFrameworkCore.design v2.0.1
o Microsoft.EntityFrameworkCore v2.0.1
o Microsoft.EntityFrameworkCore.Sqlite
can all be successfully installed in both projects
netstandard2.0
and
netcoreapp2.0
However:
Microsoft.EntityFrameworkCore.Tools.DotNet v2.0.1
can not be installed in netstandard2.0 project, which I can live with and the error makes some sense.
Restoring packages for C:_Dev\PJSTest\PJSStd\PJSStd.csproj... Package
Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.1 is not compatible
with netstandard2.0 (.NETStandard,Version=v2.0). Package
Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.1 supports:
netcoreapp2.0 (.NETCoreApp,Version=v2.0) Package restore failed.
Rolling back package changes for 'PJSStd'. Time Elapsed:
00:00:00.1634807
========== Finished ==========
BUT
Microsoft.EntityFrameworkCore.Tools.DotNet v2.0.1
can not be even be installed in a netcoreapp2.0 project
Restoring packages for C:_Dev\EFTEST\EFCore\EFCore.csproj... Detected
package downgrade: Microsoft.NETCore.App from 2.0.3 to 2.0.0.
Reference the package directly from the project to select a different
version. EFCore -> Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.1
-> Microsoft.NETCore.App (>= 2.0.3) EFCore -> Microsoft.NETCore.App (>= 2.0.0) Package restore failed. Rolling back package changes for
'EFCore'. Time Elapsed: 00:00:01.1413809
========== Finished ==========
I think there is an issue with versioning on the CoreApp dependency.
I'm happy to be corrected, but my understanding is that .NetCoreApp (v2) is the platform, whereas .NetCore.App (v2.0.5, currently) is the set of API's that target that platform.
So the fact that Microsoft.EntityFrameworkCore.Tools.DotNet V2.0.1 only points to .NetCoreApp,Version = 2.0 means it can only support the apis from that platform... which says nothing about what platforms those dependencies support. e.g. you if you take a further and look inside at the Microsoft.NetCore.App dependencies, you will see listings under .NetCoreApp,Version = 1.0 up to 2.0.
EDIT: My understanding of various .NET core versioning landscape goes as follows:
The .NET Core SDK version is 2.1.5. This allows the building of .NET standard and .NET core apps.
The Microsoft.EntityFrameworkCore.Tools.DotNet version is 2.0.1. This references .netcoreapp2.0
.netcoreapp2.0 is the platform that implements Microsoft.NetCore.App, which is currently version 2.0.5 of the runtime.
The key part of netcoreapp2.0 is its dependence on .NETStandard.Library (netstandard2.0) but netstandard2.0 does not depend on netcoreapp2.0. I think this answer explains it better than I can. So the EntityFramework cli tools won't work on a library that uses .netstandard2.0 because it targets .netcoreapp2.0. Incidentally, EFCore does work - because it targets .netstandard - just the tools won't.
In summary, the SDK that you have, at version 2.1.4, already contains the necessary .NET Core platforms and runtimes. So no downgrade to the original version 2 is required. What needs to happen is that the csproj has to be updated to target the .NET Core runtime instead in order to use the tools: <TargetFramework>netcoreapp2.0</TargetFramework>.
EDIT2: Here's a sample of a csproj file that targets .netstandard (so that UWP can reference it), and is able to use the EFCore tools.DotNet:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
</ItemGroup>
</Project>
The Microsoft.EntityFrameworkCore.Tools is a package reference that targets .NET Standard. the Microsoft.EntityFrameworkCore.Tools.DotNet is a tools reference and is treated differently to package references. So the versioning and targets are also a little different.