Reputation: 3184
I am building a test app (learning) using .Net Core 2 and Angular 5.
From the root folder where csproj file is, in powerShell following execution is resulting in an error
Command
dotnet ef migrations add "Initial" -o "Data\Migrations"
Error
PS C:\Users\T460SU\Documents\Training\Learning-Examples\Api-Angular2018\NetCore2Angular5\TestMakerFreeApp\TestMakerFreeApp> dotnet ef migrations add "Initial" -o "Data\Migrations"
No executable found matching command "dotnet-ef"
After going through various posts, looks like i am missing Microsoft.EntityFrameworkCore.Tools.DotNet
. When i try to install this package, it is resulting in the following error
PM> Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 2.0.3
GET https://api.nuget.org/v3/registration3-gz-semver2/microsoft.entityframeworkcore.tools.dotnet/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/microsoft.entityframeworkcore.tools.dotnet/index.json 70ms
Restoring packages for C:\Users\T460SU\Documents\Training\Learning-Examples\Api-Angular2018\NetCore2Angular5\TestMakerFreeApp\TestMakerFreeApp\TestMakerFreeApp.csproj...
Install-Package : Detected package downgrade: Microsoft.NETCore.App from 2.0.7 to 2.0.0. Reference the package directly from the project to select a different version.
TestMakerFreeApp -> Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.3 -> Microsoft.NETCore.App (>= 2.0.7)
TestMakerFreeApp -> Microsoft.NETCore.App (>= 2.0.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 2 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.3' has a package type 'DotnetCliTool' that is not supported by project 'TestMakerFreeApp'.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 2 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Time Elapsed: 00:00:01.1203778
Here are the nuget packages currently installed
How can i fix this? Update 1: csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<!-- Files not to publish (note that the 'dist' subfolders are re-added below) -->
<Content Remove="ClientApp\**" />
</ItemGroup>
<ItemGroup>
<None Remove="ClientApp\app\components\about\about.component.ts" />
<None Remove="ClientApp\app\components\login\login.component.ts" />
<None Remove="ClientApp\app\components\pagenotfound\pagenotfound.component.ts" />
<None Remove="ClientApp\app\components\quiz\quiz-list.component.ts" />
<None Remove="ClientApp\app\components\quiz\quiz.component.ts" />
<None Remove="ClientApp\app\interfaces\quiz.ts" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<TypeScriptCompile Include="ClientApp\app\components\about\about.component.ts" />
<TypeScriptCompile Include="ClientApp\app\components\login\login.component.ts" />
<TypeScriptCompile Include="ClientApp\app\components\pagenotfound\pagenotfound.component.ts" />
<TypeScriptCompile Include="ClientApp\app\components\quiz\quiz-list.component.ts" />
<TypeScriptCompile Include="ClientApp\app\components\quiz\quiz.component.ts" />
<TypeScriptCompile Include="ClientApp\app\interfaces\quiz.ts" />
</ItemGroup>
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<!-- In development, the dist files won't exist on the first run or when cloning to
a different machine, so rebuild them if not already present. -->
<Message Importance="high" Text="Performing first-run Webpack build..." />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
<Exec Command="node node_modules/webpack/bin/webpack.js" />
</Target>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="wwwroot\dist\**; ClientApp\dist\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
</Project>
Upvotes: 0
Views: 113
Reputation: 466
Could you please consolidate your .net core versions, so you can have a clean slate.
If you're using 2.0.x (or less), you need to add this to the project file (csproj) of the project housing your database logic
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.x" />
</ItemGroup>
Also, your add migration
command needs to include your Startup
project as well, if your database layer is a separate project. The dotnet ef
command must be executed from the database project path, and it should look something like this:
dotnet ef --startup-project ..\Path\To\Startup migrations add Initial -c YourDatabaseContext
where startup project file also needs to contain the DotNetCliToolReference
reference.
I didn't see you mentioning database contexts, but I'm sure you must have one.
If you switch to .net core version 2.1.0, everything stays the same, except that CLI tool is now part of the core entity package, so you can remove the CLI references from csproj files.
Hope it helps
Upvotes: 1