Asp.Net Core with Docker - Duplicate 'Content&

2019-07-28 04:16发布

问题:

I have a problem when I would like to deploy my app with docker. I'm using ASP.Net Core with docker.

This an error message:

/usr/local/share/dotnet/sdk/1.0.4/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.DefaultItems.targets(188,5): error : Duplicate 'Content' items were included. The .NET SDK includes 'Content' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultContentItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'wwwroot/_version.txt' [/Users/xxxxxx/Projects/api-test/TestApi/TestApi.csproj]

Here's my 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>

I think the problem is with a _version.txt file which is currently on the server (I can;t say that because I do not have an access) and It tries to duplicate it.

Would you mind to help me with that i

回答1:

The .NET SDK includes Content items from your project directory by default, so wwwroot\_version.txt is already present in your project. Your project file is then attempting to add it again, which causes the error.

You can use Update instead of Include to cause the existing content item to be updated, rather than including it twice.

So, you just have to change

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

to

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