ASP.NET Core 2 migration error. No executable found matching command "dotnet-ef" - asp.net-core

When I want to add a migration to my project I got the following error:
dotnet : No executable found matching command "dotnet-ef"
For resolving this I add the following package but I still get the same error.
Microsoft.EntityFrameworkCore.Design(2.0.0)
Microsoft.EntityFrameworkCore.Tools.DotNet(2.0.0)
I found some solution but these are based on .net-core-1 and in .net-core-2 we don't have project.json file.
update:
Here is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Configuration">
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

In order to get dotnet ef to work, you need to add a DotNetCliToolReference element to the .csproj, as follows:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
This needs to live inside an ItemGroup, something like:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
You'll also need to make sure you run dotnet ef from the same location as the .csproj file.

Link to thread
Above worked for me after many hrs trying many other thread answers. Simply cd'ing to folder containing csproj file in package console manager was all it took. dotnet ef commands all work fine then.

I know some of you will come to this question for the [No executable found matching command “dotnet-”] part of the title. In my case it was:
No executable found matching command “dotnet-My”
And.... it turns out my app name was "My App". Make sure your assembly name has no spaces in it. I changed it to "MyApp" and it loaded correctly.

Related

ASP.NET Core 2.0 InvalidOperationException: Cannot find compilation library location for package '<assemblyname>'

I have an ASP.NET Core 2.0 Razor Pages project. I am using Visual Studio 2017.
I have added one of our in-house assemblies to the project (it contains common definitions, types and functions etc). The project compiles but when I attempt to run it I get the following error.
Here is my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>2018.3.12.6</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JWT" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="dotnet-setversion" Version="*" />
</ItemGroup>
<ItemGroup>
<Reference Include="Common">
<HintPath>..\packages\Common.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Here's my Visual Studio 2017 project showing the assembly in the project.
Googling the error doesn't provide much useful information.
How do I add a reference to a custom assembly in an ASP.NET Core 2.0 Razor Pages project?
I fixed the same issue by installing Microsoft.Extensions.DependencyModel, version 2.0.3.
The solution to the problem has been posted here https://github.com/dotnet/core-setup/issues/2981
See the top comment (by tuespetre) and then the update just further down (also by tuespetre). This worked for me.

Package restore failed VS 17 for MySql

I just installed Visual studio 2017 and I wish to create a Web API. I want to use MySql as my database.
My .csproj looks like following:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
For MySql I went into NuGet package manager and searchedfor mysql.data which shows me the latest stable version to be 6.9.9. When I try to install it, I get Package restore failed error.
Am I doing something wrong?
UPDATE: I was also referring to http://insidemysql.com/getting-started-with-asp-net-core-and-mysql-connectornet/ this tutorial
I decided to go with Pomelo.EntityFrameworkCore.MySql

Wrong App.Config publish.targets MSBuild 15

I posted this question on GitHub/Microsoft/MSBuild but I'm hoping the wider community might have some early experience with this.
I'm working on converting a solution / projects from VS 2015 (.NET core preview) to VS 2017 and latest .NET Core.
The solution now builds perfectly fine in Visual Studio 2017 but the issue I encounter is when trying to run a build using MSBuild 15 (I can't use v14 because of the .NET Core projects). It fails on trying to copy the .config file from the obj\debug\net452 folder but for some reason it's adding the full .csproj name
The issue is that the Publish.Targets are doing something weird with the .config file.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(128,5):
error MSB3030: Could not copy the file "obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config" because it was not found.
[C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\code\Sitecore.Foundation.Commerce.Engine.csproj]
It's prepending the full project name (including .csproj) to the name of the config file rather than just using the AssemblyName.
In this case, Sitecore.Foundation.Commerce.Engine.csproj is the project and code is the AssemblyName (it will eventually be renamed to something better). As you can see it's looking for "Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config" which doesn't exist. code.exe.config does exist though.
I'm happy to give GitHub repo access to anyone interested in helping figure this one out with me as it's blocking us from making the repository public.
so code.exe.config is resolved as Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
OUTPUT snippet from MSBuild:
08:13:09.957 1>Target "GenerateBindingRedirectsUpdateAppConfig: (TargetId:127)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\code\Sitecore.Foundation.Commerce.Engine.csproj" (target "ResolveReferences" depends on it):
Set Property: AppConfig=obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
Added Item(s):
AppConfigWithTargetPath=
obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
TargetPath=code.exe.config
Here is the Sitecore.Foundation.Commerce.Engine.csproj content:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<PreserveCompilationContext>false</PreserveCompilationContext>
<AssemblyName>code</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>code</PackageId>
</PropertyGroup>
<!--<ItemGroup>
<None Update="wwwroot\**\*">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>-->
<ItemGroup>
<ProjectReference Include="..\..\legacyCommerce\Plugin.Sample.Habitat\Plugin.Sample.Habitat.csproj" />
<ProjectReference Include="..\..\legacyCommerce\Plugin.Sample.Payments.Braintree\Plugin.Sample.Payments.Braintree.csproj" />
<ProjectReference Include="..\..\legacyCommerce\Sitecore.Commerce.Plugin.AdventureWorks\Sitecore.Commerce.Plugin.AdventureWorks.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="6.0.0-alpha1-rtm-121216" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.1.0" />
<PackageReference Include="Serilog" Version="2.4.0" />
<PackageReference Include="Sitecore.Commerce.Core" Version="1.0.2301" />
<PackageReference Include="Serilog.Sinks.Literate" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="1.0.2" />
<PackageReference Include="Sitecore.Commerce.Provider.FileSystem" Version="1.0.2301" />
<PackageReference Include="Sitecore.Framework.Rules" Version="1.1.12" />
<PackageReference Include="Sitecore.Framework.Rules.Serialization" Version="1.1.12" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Sitecore.Framework.Diagnostics" Version="1.1.4" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
It turns out one of our NuGet references had a dependency on an incompatible package. This in turn manifested itself in a very weird way.
I'm sorry if this doesn't help anyone else but this seems to have resolved our specific issue.

Class library lost intellisense in VS2017 after .NET Core MVC auto-migration

After migrating a VS2015 MVC Core application with two projects (web app and class library) to VS2017 I've lost intellisense on all views within the class library. Pretty much everything in every single view is broken, so I'm sure it's something fairly basic that the migration tool didn't take care of for me. Even the #model directive in each razor view is an error.
The csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>Library</AssemblyName>
<PackageId>Library</PackageId>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Views\**" Exclude="bin\**;obj\**;**\*.xproj;packages\**;#(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.1.0" />
</ItemGroup>
</Project>
I tried duplicating the web.config from the web application to the root of the class library but that didn't help.
Looks like you've hit this bug:
https://github.com/aspnet/Mvc/issues/5975
Old Answer below
With the RTM version of VS 2017, you need to install the Razor Language Service extension to get back your Razor intellisense.
Unfortunately this component missed an internal ship date and as such did not make it as part of the actual VS 2017 release.
Uninstall the Razor Language Services by going to "Tools" > "Extensions and Updates".
Restart Visual Studio as per indication...
Reinstall Razor Language Services.
You will see razor intellisense working again such as asp-* tag helpers...
Two things were required to fix this issue, a change to the project SDK (<Project Sdk="Microsoft.NET.Sdk.Web">) and adding an element to set the output type to a library (<OutputType>Library</OutputType>). Full information on this GitHub issue I cross-posted.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>Library</AssemblyName>
<PackageId>Library</PackageId>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Views\**" Exclude="bin\**;obj\**;**\*.xproj;packages\**;#(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.1.0" />
</ItemGroup>
</Project>

Get test results with dotnet test on command line

I created an ASP.NET Core 1.1 xunit test project with the following csproj file:
<Project ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.6</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk" Version="1.0.0-alpha-20161104-2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0- preview-20161123-03" />
<PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLib\ClassLib.csproj"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
I am able to run the project using dotnet test using the command line but I don't see any information of how many tests passed or failed.
The version of the Dotnet Command line I am using is:
.NET Command Line Tools (1.0.0-preview4-004124)
How can I display the test results?
To make dotnet-test work, you also need to include a PackageReference to xunit.runner.visualstudio.
By the way, since you posted your question, the format for csproj has been greatly simplified. An xunit test project looks like this (as of Visual Studio 2017 RC, January and dotnet CLI 1.0.0-rc3-004350).
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="5.0.0-preview-20170125-04" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLib\ClassLib.csproj"/>
</ItemGroup>
</Project>