VS Post Build Event, copy one level above solution folder?
Asked Answered
H

5

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)

Hamiltonian answered 21/6, 2011 at 0:17 Comment(0)
D
34

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

 <PropertyGroup>
    <PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)..\Shared.Lib\$(TargetFileName)"</PostBuildEvent>
  </PropertyGroup>
Duhamel answered 21/6, 2011 at 0:20 Comment(3)
what if I just want to copy one particular binary, and not every output file?Hamiltonian
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.Duhamel
This answer did not work for me. This one does. The problem lies in the `..` in quote; it should be outside.Catchings
T
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.

Tertullian answered 20/9, 2012 at 21:31 Comment(1)
thnx a lot. It worked with me as well. but with copy not xcopyRodrigorodrigue
V
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

Vitalis answered 23/6, 2011 at 12:36 Comment(1)
Make sure the path you choose exists, it didn't work for me until the path actually existed.Hamiltonian
H
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.

Hydranth answered 7/7, 2019 at 14:12 Comment(0)
G
-1

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

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

Gordon answered 31/5, 2016 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.