efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EntityFramework.Tools Mac OSX 10.21

Open joacar opened this issue 10 years ago • 18 comments

Steps to reproduce

  1. Visual Studio for Mac (and necessary binaries)
  2. Create web application
  3. Install Microsoft.EntityFramework.Tools.DotNet 1.1.0-preview4-final

The issue

Trying to install tooling do run dotnet ef commands

Retrieving package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.1.0-preview4-final' from 'nuget.org'. Install failed. Rolling back... Package 'Microsoft.EntityFrameworkCore.Tools.DotNet.1.1.0-preview4-final' does not exist in project 'App' Executing nuget actions took 620.74 ms Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.1.0-preview4-final' has a package type 'DotnetCliTool' that is not supported by project 'App'.

Further technical details

EF Core version: 1.1.0 [assembly: AssemblyFileVersion ("1.1.0.21115")] [assembly: AssemblyInformationalVersion ("1.1.0-rtm-22752")]

Operating system: Visual Studio for Mac OSX 10.12.21

Other details about my project setup: dotnet --version 1.0.0-preview3-004056 sdk 1.0.0-preview3-004056 (/usr/local/share/dotnet/sdk

joacar avatar Nov 28 '16 11:11 joacar

NuGet currently doesn't support installing .NET CLI Tool packages. You need to manually edit the project.json to register it...

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"    
  },

rowanmiller avatar Nov 30 '16 18:11 rowanmiller

Closing as I think I have answered this, but reply if not and I will reopen.

rowanmiller avatar Nov 30 '16 18:11 rowanmiller

Thanks will try it out!

joacar avatar Nov 30 '16 18:11 joacar

Since I'm running Visual Studio for Mac I added it to .csproj as follows

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
    <Version>1.1.0-preview4-final</Version>
</PackageReference>

The file package.json was nowhere to be found and, as far as I've read, it pretty much has been replaced by .csproj(correct me if I'm wrong - new to .NET core).

Well enough rambling: it still doesn't work.

$ dotnet ef No executable found matching command "dotnet-ef"

So I found a package.json file and included it as well and added the tools section. dotnet restore does nothing but nuget restore try to do something, but fails since there is missing pieces.

Currently this is my package.json (probably completely incorrect)

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final"
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.0.0-preview1-final",
  "imports": [
    "portable-net45+win8+dnxcore50",
    "portable-net45+win8"
  ]
}
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

The output from nuget restore is

Restoring packages for tool 'Microsoft.EntityFrameworkCore.Tools' in /Users/.../src/App/project.json...
  GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/index.json 516ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/1.0.0-preview1-final/microsoft.entityframeworkcore.tools.1.0.0-preview1-final.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/1.0.0-preview1-final/microsoft.entityframeworkcore.tools.1.0.0-preview1-final.nupkg 560ms
Installing Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final.
Committing restore...
/Users/.../src/App/project.json
Restore completed in 230965ms.

NuGet Config files used:
    /Users/user/.config/NuGet/NuGet.Config

Feeds used:
    https://api.nuget.org/v3/index.json

Installed:
    193 package(s) to /Users/.../src/App/project.json

Where those 193 packages went I've no idea and for what reason they were even installed I don't understand (perhaps the different frameworks dnxcore,dnx,portable and so on that is not part of .netstandard1.1 that my app is targeting)

Anyhow: it still doesn't work. Any clues?

What is the plan for .csproj and project.json? Will both be needed when running Visual Studio for Mac?

.csproj

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <ReleaseVersion>1.0.0-beta1</ReleaseVersion>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
    <EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
    <Compile Remove="Controllers\ListItem.cs" />
    <Compile Remove="Models\Url.cs" />
    <Compile Remove="Authorization\CureAuthorizationHandler.cs" />
  </ItemGroup>

  <ItemGroup>
    <!-- Tools -->
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
      <Version>1.1.0-preview4-final</Version>
    </PackageReference>
    <!-- Tools end -->
    <PackageReference Include="Microsoft.NET.Sdk.Web">
      <Version>1.0.0-alpha-20161104-2-112</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.Console">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Json">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Authentication">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Logging">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Tokens">
      <Version>5.1.0</Version>
    </PackageReference>
    <PackageReference Include="System.IdentityModel.Tokens.Jwt">
      <Version>5.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Protocols">
      <Version>2.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect">
      <Version>2.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Options">
      <Version>1.1.0</Version>
    </PackageReference>
  </ItemGroup>
  <!--Items removed for brevity -->
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

joacar avatar Dec 01 '16 07:12 joacar

@rowanmiller Do you have any ideas what might be wrong? Don't know what to try next - running out of ideas

joacar avatar Dec 02 '16 09:12 joacar

For preview3 (csproj-based) tooling, you'll need to add the following.

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
    <Version>1.0.0-msbuild1-final</Version>
</DotNetCliToolReference>

bricelam avatar Dec 02 '16 18:12 bricelam

Also, I don't think the 1.1 runtime is supported on the preview3 tooling. At the least, you'll probably need to add the following package references. But even then it still may not work.

<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
  <Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
  <Version>1.0.0-msbuild1-final</Version>
</PackageReference>

bricelam avatar Dec 02 '16 18:12 bricelam

@bricelam That did the trick. Unfortunately after running it the first time I can't run dotnet ef again. Get **no executable matchin 'dotnet-ef'

Edit After running the tool the reference Microsoft.EntityFrameworkCore.Tools.DotNet was removed

Edit2 There is a file added to VS for Mac with the name Microsoft.EntityFrameworkCore.Tools.DotNet and first time I removed it (since VS say it doesn't exists). Might be because of that the tooling stopped working. I will leave it now when it works :)

joacar avatar Dec 02 '16 19:12 joacar

Yep. Definitely still a preview. Personally, I'm surprised to hear that VS for Mac works at all with MSBuild .NET Core projects.

bricelam avatar Dec 02 '16 22:12 bricelam

It doesn't work as well as one had hopped though :). Struggling with referencing a Core class library (netstandard1.6) in my asp.net core web (.netcoreapp1.1).

Referencing it directly make it compile but then the assembly file cannot be found. Tried to add it to my "local nuget feed" and install it but that fails since it wants to upgrade the tooling (but fails).

Third try adding it to .csproj directly and performing dotnet clean && dotnet restore adds the nuget but cannot find the assembly.

joacar avatar Dec 02 '16 22:12 joacar

any luck adding "Microsoft.EntityFrameworkCore.Tools.DotNet" on visual studio for mac? I am using dotnet version 1.0.0-preview3-004056

vivek306 avatar Dec 10 '16 15:12 vivek306

@vivek306 Yes! Paste below in ItemGroup

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"> <Version>1.0.0-msbuild1-final</Version> </DotNetCliToolReference> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"> <Version>1.0.0-msbuild1-final</Version> </PackageReference> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools"> <Version>1.0.0-msbuild1-final</Version> </PackageReference>

The CLI-reference will show up as missing in solution explorer (at least for me) and dont remove it since the reference will be removed.

joacar avatar Dec 11 '16 15:12 joacar

Great that works :).. did u have issues with AddUserSecrets? it pops up with parameter less error for ApplicationDBContext but EF works as it should when I comment that.

vivek306 avatar Dec 11 '16 16:12 vivek306

Havent used that tool. Can check during the day if i can get it to work. What version are you using?

joacar avatar Dec 12 '16 07:12 joacar

it seems, what i came across is a know issue (https://stackoverflow.com/questions/40858155/ef-core-1-1-to-webapi-core-add-migration-fails) not related to EF. using the dotnet preview 3 with 1.1 runtime

vivek306 avatar Dec 12 '16 16:12 vivek306

For EntityFrameworkCore 2.0, I added the following line similar to what bricelam told above. It worked fine.

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-msbuild1-final"/>

But, It will show-up a warning. Thats ok.

warning NU1603: DotnetCliToolReference-Microsoft.EntityFrameworkCore.Tools.DotNet depends on Microsoft.EntityFrameworkCore.Tools.DotNet (>= 2.0.0-msbuild1-final) but Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.0-msbuild1-final was not found. An approximate best match of Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.0-preview1-final was resolved.

Thanks!

technicalganesh avatar Sep 04 '17 13:09 technicalganesh

@technicalganesh - The package version is 2.0.0 (aligned with other EF Core packages) instead of 2.0.0-msbuild1-final.

smitpatel avatar Sep 05 '17 19:09 smitpatel

If you are using Visual Studio 2017, actually you dont need "Microsoft.EntityFrameworkCore.Tools.DotNet" instead of it install the "Microsoft.VisualStudio.Web.CodeGeneration.Design" From Tools > NuGet Package Manager > Package Manager Console Run the following command Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

procansoft avatar Mar 12 '18 18:03 procansoft