Msbuild: Visual Studio doesn't respect CopyToOutputDirectory=Always, dotnet build does

Created on 18 May 2018  路  4Comments  路  Source: dotnet/msbuild

Steps to reproduce

Project file

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <LangVersion>7.2</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="*-config.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Always</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Compile Remove="logs\**" />
    <Content Remove="logs\**" />
    <EmbeddedResource Remove="logs\**" />
    <None Remove="logs\**" />
  </ItemGroup>

  <ItemGroup>
    <!-- Saffron packages -->
    <PackageReference Include="RedRiver.SaffronCore" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.Auth" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.AspNetCore" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.Autofac" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.EntityFramework" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.EntityFramework.AuthStore" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.EntityFramework.Tooling" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.RedisCore" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.Redis.Queues" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.Cqrs" Version="2.0.0-alpha1-999000428" />
    <PackageReference Include="RedRiver.Saffron.AutoMapper" Version="2.0.0-alpha1-999000428" />
  </ItemGroup>

  <ItemGroup>
    <!-- Other packages -->
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Database\Migrations\" />
  </ItemGroup>

</Project>

Directory contents (and more):

/
- my-config.json
- my-other-config.json

Command line

n/a

Expected behavior

Updated *-config.json files copied to output folder using dotnet build OR Visual Studio

Actual behavior

Updated *-config.json files only copied to output folder using dotnet build, does not occur Visual Studio

(If the file doesn't exist it is copied, just not an updated one)

Environment data

msbuild /version output:

'msbuild' is not recognized as an internal or external command,
operable program or batch file.

OS info: Windows 10 Pro

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
Visual Studio 2017 15.7.1

Most helpful comment

I'm experiencing the same problem. I have an MSBuild project with two javascript files that I want to copy to the output folder. Neither are being copied by MSBuild, despite having <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> set in the project for both files.

All 4 comments

I'm experiencing the same problem. I have an MSBuild project with two javascript files that I want to copy to the output folder. Neither are being copied by MSBuild, despite having <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> set in the project for both files.

Same issue here - did any of you get this one figured out?

Similar issue. I converted some .NET Framework projects from old CSPROJ to new CSPROJ structure. I discovered that I need to do a Rebuild to have the files copied. E.g. A simple change in a JSON settings file would not get copied over till I do a Rebuild.

In the older .NET Framework style CSPROJ the copy action would consistently take place during both Build and Rebuild actions.

This issue looks trivial at first. But, it becomes significant when I am making changes to various settings files and attempting to do a quick test. I have to always do a Rebuild, which usually ends being much longer than a Build.

I can consistently reproduce this issue with any .NET Standard 20/Core class library projects. I am forced to do a Rebuild to have the updated files copied over to the output folder.

Older .NET Framework projects continue to work fine. The modified files get copied over to the output folder when I do a Build.

Visual studio version
VS 2017, 15.9.3

Was this page helpful?
0 / 5 - 0 ratings