Sdk: Can't copy file from project root to build output directory

Created on 13 Jul 2017  ยท  1Comment  ยท  Source: dotnet/sdk

Overview

I'm attempting to copy a file (coremodule.psd1) from my project root into the target build directory, however the action is silently failing. The build allegedly succeeds, and my target build output path contains the project DLL, however the coremodule.psd1 file is not copied to the build directory.

Steps to reproduce

  1. Create class library project
  2. Setup nuget.config
  3. Configure .csproj file with copy task
  4. Run dotnet restore
  5. Run dotnet build

Project Folder Structure

โžœ  coremodule tree
.
โ”œโ”€โ”€ Class1.cs
โ”œโ”€โ”€ code.csproj
โ”œโ”€โ”€ coremodule.psd1
โ””โ”€โ”€ nuget.config

code.csproj file

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

  <PropertyGroup>
    <TargetFramework>netstandard1.6</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include = "Microsoft.PowerShell.SDK" Version = "6.0.0-beta.4" />
  </ItemGroup>

  <Target Name = "CopyFiles">
    <Copy DestinationFolder="$(OutputPath)" SourceFiles="coremodule.psd1" SkipUnchangedFiles = "false" />
  </Target>
</Project>

nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
    <add key="CI Builds (dotnet-core)" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Expected behavior

File in project directory is copied to target build / output directory.

Actual behavior

File in project directory is not copied to target build / output directory.

Environment data

dotnet --info output:

NOTE: This is running inside of a Linux container on Docker for Mac.

root@c00e91a5249a:/code# dotnet --info
.NET Command Line Tools (2.0.0-preview2-006497)

Product Information:
 Version:            2.0.0-preview2-006497
 Commit SHA-1 hash:  06a2093335

Runtime Environment:
 OS Name:     debian
 OS Version:  9
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/2.0.0-preview2-006497/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview2-25407-01
  Build    : 40c565230930ead58a50719c0ec799df77bddee9

Most helpful comment

Hi pcgeek86,

_dotnet build_ will eventually invoke "build" target. You are adding a target without wire it up to "build"

you can do it like this

<Target Name = "CopyFiles" AfterTargets="build">
    <Copy DestinationFolder="$(OutputPath)" SourceFiles="coremodule.psd1" SkipUnchangedFiles = "false" />
  </Target>

>All comments

Hi pcgeek86,

_dotnet build_ will eventually invoke "build" target. You are adding a target without wire it up to "build"

you can do it like this

<Target Name = "CopyFiles" AfterTargets="build">
    <Copy DestinationFolder="$(OutputPath)" SourceFiles="coremodule.psd1" SkipUnchangedFiles = "false" />
  </Target>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

darrensimio picture darrensimio  ยท  3Comments

aguacongas picture aguacongas  ยท  3Comments

gkhanna79 picture gkhanna79  ยท  3Comments

noelitoa picture noelitoa  ยท  3Comments

joffreykern picture joffreykern  ยท  3Comments