带Docker的Asp.Net Core - 重复内容'物品包括在内

时间:2017-05-23 05:09:14

标签: c# asp.net .net docker asp.net-core

当我想使用docker部署我的应用时遇到问题。 我使用ASP.Net Core和docker。

这是一条错误消息:

  

/usr/local/share/dotnet/sdk/1.0.4/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.DefaultItems.targets(188,5):   错误:重复'内容'物品包括在内。 .NET SDK包括   '内容'默认情况下,项目目录中的项目。你也可以   从项目文件中删除这些项目,或设置   ' EnableDefaultContentItems'属于' false'如果你想   明确地将它们包含在项目文件中。欲获得更多信息,   见https://aka.ms/sdkimplicititems。重复的项目是:   ' wwwroot的/ _version.txt'   [/Users/xxxxxx/Projects/api-test/TestApi/TestApi.csproj]

这是我的csproj

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

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1.1</TargetFramework>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    <UserSecretsId>0a7aa24d-009c-4d0b-b0fd-e8be397b0784</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="6.0.2" />
    <PackageReference Include="CoreCompat.System.Drawing" Version="1.0.0-beta006" />
    <PackageReference Include="Google.Cloud.Storage.V1" Version="1.1.0-beta01" />
    <PackageReference Include="HtmlAgilityPack.NetCore" Version="1.5.0.1" />
    <PackageReference Include="MailKit" Version="1.16.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="1.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.1.0-beta2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="7.0.7-m61" />
    <PackageReference Include="RazorLight" Version="1.1.0" />
    <PackageReference Include="RazorLight.MVC" Version="1.0.4" />
    <PackageReference Include="Serilog" Version="2.5.0-dev-00817" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="1.4.1-dev-10155" />
    <PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.1" />
    <PackageReference Include="Serilog.Sinks.Console" Version="2.2.0-dev-00721" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="1.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="1.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="1.0.0" />
    <PackageReference Include="WkWrap.Core" Version="1.0.2" />
    <PackageReference Include="ZXing.Net" Version="0.15.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="SQL\" />
    <Content Include="wwwroot\_version.txt">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
</Project>

我认为问题出在_version.txt文件中,该文件当前在服务器上(我可以说,因为我没有访问权限)并且它试图复制它。

你介意帮助我吗

1 个答案:

答案 0 :(得分:1)

默认情况下,.NET SDK包含项目目录中的Content项,因此项目中已存在wwwroot\_version.txt。然后您的项目文件再次尝试添加它,这会导致错误。

您可以使用Update代替Include来更新现有内容项,而不是将其包含两次。

所以,你只需要改变

<Content Include="wwwroot\_version.txt">
  <CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>

<Content Update="wwwroot\_version.txt">
  <CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>