I have just created a brand new project in Visual Studio 2022. The project is targeting .NET 6.0, EF Core 6.0.7, and I have added the tools package so I can attempt to scaffold my existing database.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>True</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>False</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!--<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7" />-->
</ItemGroup>
</Project>
You will notice that one line is commented out (...DotNetCliToolReference...), more on that in a minute.
When I try my scaffolding command, I am told that the command is not available, either via the PowerShell command or by the standard dotnet ef dbcontext scaffold ... command.
Could not execute because the specified command or file was not found.
Possible reasons for this include:
You misspelled a built-in dotnet command.
You intended to execute a .NET program, but dotnet-ef does not exist.
You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
THe command I am running is:
dotnet ef dbcontext scaffold "Data Source=MyServer;Initial Catalog=MyDatabase" Microsoft.EntityFrameworkCore.SqlServer
With some research I discovered and added the DotNetCliToolReference line to add to my project file. After I add that I am immediately greeted with a new error.
NU1202 Package Microsoft.EntityFrameworkCore.Tools 6.0.7 is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Package Microsoft.EntityFrameworkCore.Tools 6.0.7 supports: net6.0 (.NETCoreApp,Version=v6.0)
As you can see from my project file, I am not running .NET Core v2.2!!!
Any ideas on what I am doing wrong?
.NET tools aren't installed using DotNetCliToolReference. That's only used up to .NET Core 2.2. The EF docs don't mention it at all.
.NET Tools are managed with the dotnet tool command. You can see all the available commands and options with dotnet tool --help.
Tools are published as NuGet packages in NuGet.org. They can be installed with
dotnet tool install --global tool-name
The EF tool docs show that the correct command is
dotnet tool install --global dotnet-ef
Upgrading works the same as other dotnet tools
dotnet tool update --global dotnet-ef
Scaffolding in general is explained in the Reverse Engineering (Scaffolding) page
Related
I have an existing dotnet core 3.1 web app that builds and deploys to an azure app service. it works fine. I am trying to containerize the app.
the build is fine, but when the container runs it gives me
It was not possible to find any compatible framework version
The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' (x64) was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
my docker
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY myreports/*.csproj .
RUN dotnet restore
# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app
# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:6.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "myreports.dll"]
I've tried a variety of docker images(inc dotnet/core) and its the same.
my csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>myreports</RootNamespace>
<UserSecretsId>ed68b972-ed89-4115-8e6c-5f0d032efa4d</UserSecretsId>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.8.0" />
<PackageReference Include="FastReport.Core3.Web" Version="2021.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.16.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.16.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!--PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.14.0" /-->
<PackageReference Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="3.1.9" />
<PackageReference Include="Microsoft.Azure.EventGrid" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.5.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
</ItemGroup>
</Project>
I suspect its this
<PackageReference Include="FastReport.Core3.Web" Version="2021.3.0" />
But its required as its core to the project. What gets me is that my config in the (working) app settings is:
Your project is targeting .NET Core 3.1 but your Dockerfile is referencing 6.0 tags, which refers to .NET 6. A .NET Core 3.1 app won't be able to run in a 6.0 runtime container. You should update your Dockerfile to reference 3.1 instead of 6.0.
Update
Since there's also a dependency on the Microsoft.WindowsDesktop.App framework, you'll need to manually add that framework into the runtime. By default, the runtime image only contains the Microsoft.NETCore.App.
However, the sdk image does contain the Microsoft.WindowsDesktop.App framework. This allows you to use an sdk container to build a project that has a Microsoft.WindowsDesktop.App framework dependency. You just can't run, by default, in the runtime container because it's very atypical to run an app in a container that has such a dependency.
What this all means is that you can copy the Microsoft.WindowsDesktop.App framework from the sdk to the runtime container which should resolve your issue. I've updated your Dockerfile to include COPY instruction which does this:
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY myreports/*.csproj .
RUN dotnet restore
# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app
# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:3.1
COPY --from=build ["C:/Program Files/dotnet/shared/Microsoft.WindowsDesktop.App", "C:/Program Files/dotnet/shared/Microsoft.WindowsDesktop.App/"]
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "myreports.dll"]
As the package name indicates it is a windows dependant component. Try running your application on a windows container not linux.
I believe I was able to resolve this by changing the final image to :
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
Following your answer on changing the image to mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
If you did not change your csproj you now have a .NET Core 3.1 app running on .NET 4.8. This could lead to subtle runtime problems. (citation needed)
I would strongly suggest upgrading your csproj to .NET 6 since .NET 3.1 is running out of support in some months anyways.
I might be mistaken but the first step would be to change <TargetFramework>netcoreapp3.1</TargetFramework> to <TargetFramework>net6.0</TargetFramework> and of course follow an upgrade guide online https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-60?view=aspnetcore-6.0&tabs=visual-studio
I have an app I recently upgraded from Dotnet Core 2.2.
It runs from the command line:
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.101
Commit: d05174dc5a
Runtime Environment:
OS Name: ubuntu
OS Version: 20.10
OS Platform: Linux
RID: ubuntu.20.10-x64
Base Path: /usr/share/dotnet/sdk/5.0.101/
Host (useful for support):
Version: 5.0.1
Commit: b02e13abab
.NET SDKs installed:
3.1.404 [/usr/share/dotnet/sdk]
5.0.101 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
…
$ dotnet build
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
Bundler: Begin processing bundleconfig.json
Bundler: Done processing bundleconfig.json
uk.ac.sahfos.cpr.console.web -> /home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/bin/Debug/netcoreapp3.1/uk.ac.sahfos.cpr.console.web.dll
uk.ac.sahfos.cpr.console.web -> /home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/bin/Debug/netcoreapp3.1/uk.ac.sahfos.cpr.console.web.Views.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.43
$ dotnet run
Content root path: /home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web
Now listening on: http://localhost:49755
Application started. Press Ctrl+C to shut down.
but if I try to run it from inside VS Code I get:
Using launch settings from '/home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/Properties/launchSettings.json' [Profile '(Default)']...
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.All', version '2.2.0' was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
Now, the launchsettings.json file contains no mention of the framework, and the .csproj has no reference to Microsoft.AspNetCore.All (or Microsoft.AspNetCore.App for that matter):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="2.6.362"/>
<PackageReference Include="Grid.AspNetCore.Mvc" Version="1.0.0"/>
<PackageReference Include="HtmlAgilityPack" Version="1.11.16"/>
<PackageReference Include="Humanizer" Version="2.6.2"/>Microsoft.AspNetCore.All
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="3.1.4"/>
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="3.1.4"/>
<PackageReference Include="EFCore.NamingConventions" Version="1.1.0"/>
<PackageReference Include="GeoAPI.Core" Version="1.7.5"/>
<PackageReference Include="System.Composition" Version="1.0.31"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.11"/>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"/>
</ItemGroup>
</Project>
So, where is it picking up this requirement for 2.2?
Naturally, immediately after posting, I found the answer.
Despite the message:
Using launch settings from '/home/derek/MBA/uk.ac.sahfos.cpr.console.web/uk.ac.sahfos.cpr.console.web/Properties/launchSettings.json' [Profile '(Default)']...
launchSettings.json is irrelevant. It's the launch.json file that has a hard-coded path to the framework and warns:
// If you have changed target frameworks, make sure to update the program path.
When I run the dotnet test task, the tests run correctly but when generating the report file in xml format I get the following error:
/home/adminuser/.nuget/packages/coverlet.msbuild/2.3.1/build/netstandard2.0/coverlet.msbuild.targets(17,5):
error : Method not found: 'Void
System.IO.FileStream..ctor(System.String, System.IO.FileMode,
System.IO.FileAccess, System.IO.FileShare)'.
The project configuration file (.csproj) is as follows:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
</ItemGroup>
</Project>
Note:
The pipeline was running fine but from one moment to the next it started generating the following error
You're using self-hosted agent to run the pipeline, so the command should be executed in your local environment. You can try steps below to resolve the issue:
1.Clean the package cache, delete the bin and obj folder and run the dotnet test command again.
2.Update coverlet.msbuild package from 2.3.1 to latest 2.9.0.
In addition:
To generate xml report(coverage.cobertura.xml): You should use coverlet.collector package with command dotnet test --collect:"XPlat Code Coverage".
To generate json report(coverage.json): You should use coverlet.msbuild package with command dotnet test /p:CollectCoverage=true.
More details check coverlet-coverage/coverlet.
Using .NET Core, I'm trying to create a new Nuget without it installing the it's own dependencies.
This is my new NuGet package csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<TargetFrameworks>net461</TargetFrameworks>
<PackageId>MyFirstNuget</PackageId>
<Version>1.0.1-prerelease</Version>
<Authors></Authors>
<Company></Company>
<Description></Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SccLocalPath>.</SccLocalPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SomePackage" Version="7.12.4" />
</ItemGroup>
</Project>
When I install the package on a project it installs the package "SomePackage"
Is there an option not to install all the dependencies?
When working with PackageReference there are some ways to control dependency assets.
As stated here:
IncludeAssets: These assets will be consumed
ExcludeAssets: These assets will not be consumed
PrivateAssets: These assets will be consumed but won't flow to the parent project
In your case you need to use PrivateAssets like this:
<ItemGroup>
<PackageReference Include="SomePackage" Version="7.12.4">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
since your project uses SomePackage, but you don't want SomePackage installed when you use your new NuGet package.
I think PrivateAssets can help you. Try changing your PackageReference to
<PackageReference Include="UmbracoCms" Version="7.12.4">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
I installed .NET Core 2.1.105 on ubuntu from here
and created the sample web api project with dotnet new api-test
Then I tried to add the dotnet watcher package with
dotnet add package Microsoft.DotNet.Watcher.Tools
And when I issue a dotnet restore I get the following error:
$ dotnet restore
Restoring packages for ~/devel/apps/dotnet/api_test/api_test.csproj...
Restore completed in 101.8 ms for ~/devel/apps/dotnet/api_test/api_test.csproj.
~/devel/apps/dotnet/api_test/api_test.csproj : error NU1605: Detected package downgrade: Microsoft.NETCore.App from 2.0.6 to 2.0.0. Reference the package directly from the project to select a different version.
~/devel/apps/dotnet/api_test/api_test.csproj : error NU1605: api_test -> Microsoft.DotNet.Watcher.Tools 2.0.1 -> Microsoft.NETCore.App (>= 2.0.6)
~/devel/apps/dotnet/api_test/api_test.csproj : error NU1605: api_test -> Microsoft.NETCore.App (>= 2.0.0)
Restore failed in 1.26 sec for ~/devel/apps/dotnet/api_test/api_test.csproj.
And this is my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.7" />
<PackageReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>
</Project>
-- update
as stated in the answers bellow, dotnet watch should be included be part of he SDK from version 2.1, so I did this little test:
$ dotnet --version
2.1.105
$ dotnet new webapi -o tmp_api
The template "ASP.NET Core Web API" was created successfully.
$ cd tmp_api/
$ dotnet watch run
No executable found matching command "dotnet-watch"
--
dotnet watch is available from preview2 version onwards (which is available here)
Starting from .NET Core 2.1 Preview 2 the CLI tools like dotnet watch are now part of the SDK:
We found that these tools were so popular that having to add them to individual projects didn’t seem like the right design, so we made them part of the SDK.
These tools were previously DotNetCliToolReference tools. They are no longer delivered that way. You can delete the DotNetCliToolReference entries in your project file when you adopt .NET Core 2.1.
dotnet watch is a CLI tool, not a package your code can depend on. The official docs explain that you need to use DotNetCliToolReference:
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
You shouldn't be using it as a PackageReference.