.net核心web api与.net标准库EF

时间:2018-06-02 19:27:32

标签: c# asp.net-core

我在.net核心web api项目中遇到了最棘手的问题我添加了一个.net标准库,它首先包含我的模型和EF代码。这一切都在我部署到IIS Express时有效,但当我尝试将其发布到IIS时,构建失败。

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\logs\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.5.4" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
      <Version>1.0.0-*</Version>
    </DotNetCliToolReference>
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\mobileapp\forms\xxxCallManager\xxxDalCoreStandard\xxxDalCoreStandardxxxlDalCoreStandard.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System.Text.Encoding.CodePages">
      <HintPath>..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Text.Encoding.CodePages.dll</HintPath>
    </Reference>
  </ItemGroup>


</Project>

正如你所看到的那样,他们没有提到system.refelection,所以我只能在我的标准项目中将其中的一个用于下面弄乱它是我的standard.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />

  </ItemGroup>
    <ItemGroup>
   <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
</ItemGroup>
</Project>

我得到的错误现在如下我尝试添加system.reflection的nuget但仍然没有快乐

enter image description here

修改1 下面的建议有点帮助,但现在我遇到了这个错误。

  

严重级代码描述项目文件行抑制状态   错误命令&#34;&#34; dotnet&#34; exec --runtimeconfig   &#34; C:\工作\ xxxApp \ xxxlApis \ BIN \发布\ netcoreapp2.0 \ FuelApis.runtimeconfig.json&#34;   --depsfile&#34; C:\ Work \ FxxxApp \ xxxlApis \ bin \ Release \ netcoreapp2.0 \ xxxApis.deps.json&#34;   &#34; C:\程序   文件\ DOTNET \ SDK \ NuGetFallbackFolder \ microsoft.aspnetcore.mvc.razor.viewcompilation \ 2.0.3 \构建\ netstandard2.0 \ Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll&#34;   @&#34;物镜\推出\ netcoreapp2.0 \ microsoft.aspnetcore.mvc.razor.viewcompilation.rsp&#34;&#34;   退出代码1. xxxlApis 0

1 个答案:

答案 0 :(得分:0)

您在第一个项目中使用的是错误版本的EF工具,它看起来像1.0预览版,它应该是:

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.*" />

我也会删除这部分:

<ItemGroup>
<Reference Include="System.Text.Encoding.CodePages">
  <HintPath>..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>

我认为你不需要那个特别是提示路径部分。我会尝试完全删除