如何在没有project.json的情况下使用Dotnet Core 1.1 CLI工具?

时间:2017-01-20 19:38:05

标签: .net visual-studio msbuild .net-core

我在Visual Studio 2017 RC中构建了一个针对Dotnet Core 1.1的Web应用程序。根据{{​​3}}和其他地方,MS已宣布project.json正在退休并受到MSBUILD .csproj文件的青睐。问题是dotnet CLI似乎无法使用.csproj,例如使用dotnet ef ...总是会产生错误,而不是找不到它的二进制文件(即使{{ PowerShell命令在VS中工作 - 这是由于缺少project.json而有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:2)

尝试添加

Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0-msbuild2-final
密钥是msbuild部分,它对我有用。供您参考,我的整个.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>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
    <EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk.Web">
      <Version>1.0.0-alpha-20161104-2-112</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc">
    <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics">
      <Version>1.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration">
      <Version>1.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.Console">
      <Version>1.0.0</Version>
    </PackageReference>
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql">
      <Version>1.1.1-prerelease-10012</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild2-final" />
  </ItemGroup>

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

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

</Project>