I am trying to overwrite the obj\Release .exe with a protected .exe that's placed in \obj\Release\Protected after the build. The code I am using is below, and it resides at the very end of the environment, immediately before </Project>
. However, for some reason the .exe is not getting copied.
Do I need to try this from the Project Properties-->Compile-->Post Build Events instead?
<ItemGroup>
<MyProjectOutput Include="d:\myproject\obj\Release\Protected\myapp.exe"/>
</ItemGroup>
<Target Name="CopyFiles">
<Copy SourceFiles="@(MyProjectOuput)" DestinationFolder="d:\myproject\obj\Release" />
</Target>
CodePudding user response:
It's not enough to just have the target in your project file. It has to be set up appropriately so that it will be picked up by the build sequence. Naming it "CopyFiles" will not accomplish this.
There are a few well-known target names that are called as part of the build sequence (you should be able to find MSDN documentation on this). I believe "AfterBuild" is one of these. So your target should look something like this:
<Target Name="AfterBuild">
<Copy SourceFiles="@(MyProjectOuput)" DestinationFolder="d:\myproject\obj\Release" />
</Target>
You may also want to consider adding Inputs
and Outputs
attributes on the targets to help with dependency analysis, and you may also want to consider adding a BeforeClean
or AfterClean
target to clean up the post-copy files.