17

I currently have

  <PropertyGroup>
    <PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)Shared.Lib\$(TargetFileName)"</PostBuildEvent>
  </PropertyGroup>

I want to do something like this, but one level above $(SolutionDir)

bevacqua
  • 47,502
  • 56
  • 171
  • 285

5 Answers5

34

You can use ..\ to move up a directory.

 <PropertyGroup>
    <PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)..\Shared.Lib\$(TargetFileName)"</PostBuildEvent>
  </PropertyGroup>
joncham
  • 1,584
  • 10
  • 14
  • what if I just want to copy one particular binary, and not every output file? – bevacqua Jun 21 '11 at 00:24
  • Are you saying that line currently copies more than one file? I would expect $(TargetPath) to point to the exe/library you are building for the project. – joncham Jun 21 '11 at 00:30
  • This answer did not work for me. [This one](https://stackoverflow.com/a/12521225/6655465) does. The problem lies in the `..\` in quote; it should be outside. – Eduardo Pignatelli Jan 08 '18 at 10:32
13

Solution:

copy "$(TargetPath)" "$(SolutionDir)"..\"Shared.Lib\$(TargetFileName)"

If you have ..\ within the quotation marks, it will take it as literal instead of running the DOS command up one level.

jonsca
  • 10,218
  • 26
  • 54
  • 62
sourcecode108
  • 131
  • 1
  • 2
3

This is not working in VS2010 .. is not resolved but becomes part of the path

Studio is running command something like this copy drive$:\a\b\bin\debug drive$:\a\b..\c

Kiran Bheemarti
  • 1,439
  • 2
  • 12
  • 14
1

In .Net Core edit csproj file:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="copy /Y &quot;$(TargetPath)&quot; &quot;$(SolutionDir)&quot;..\&quot;lib\$(TargetFileName)&quot;" />
</Target>

/Y Suppresses prompting to confirm you want to overwrite an existing destination file.

Ali Bayat
  • 3,561
  • 2
  • 42
  • 43
-1

xcopy "$(TargerDir)." "$(SolutionDir)..\Installer\bin\"

Note: "../" is used for One level up folder structure