Skip to content

dotnet build ignores .config files from .csproj CopyToOutputDirectory #3669

Open
@retifrav

Description

@retifrav

I noticed that .csproj rule

<ItemGroup>
  <None Update="log4net.config" CopyToOutputDirectory="Always" />
</ItemGroup>

is ignored for files with .config extension when performing dotnet build.

I've done some testing with the following project:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <ItemGroup>
    <None Update="ololo.config" CopyToOutputDirectory="Always" />
    <None Update="ololo.config2" CopyToOutputDirectory="Always" />
    <None Update="ololo.confi" CopyToOutputDirectory="Always" />
    <None Update="log4net.config" CopyToOutputDirectory="Always" />
    <None Update="some.txt" CopyToOutputDirectory="Always" />
  </ItemGroup>

  ...

</Project>

The following files are successfully copied to the output directory:

  • ololo.config2
  • ololo.confi
  • some.txt

But these files are not copied:

  • ololo.config
  • log4net.config

Like I said, this happens on dotnet build. At the same time dotnet publish works fine and copies all the files.

My environment:

> dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.2.402
 Commit:    c7f2f96116

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.402\

Host (useful for support):
  Version: 2.2.7
  Commit:  b1e29ae826

.NET Core SDKs installed:
  2.2.402 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions