Is it possible to run AfterBuild target from csproj.user file?

218 views Asked by At

I want to extend my local build process in .csproj.user file which is not tracked within our git repository. Previously I used PostBuildEvent but suddenly I discover that it does not work well with variables: https://github.com/dotnet/sdk/issues/677

Works from both .csproj and .csproj.user but cannot have variables:

<PostBuildEvent>xcopy "C:\workspace\project\bin\Debug\my.dll" "C:\Program\bin" /y</PostBuildEvent>

Works only if placed in the end of .csproj but not in .csproj.user:

<Target Name="AfterBuild">
    <Copy SourceFiles="$(ProjectDir)\$(OutputPath)\my.dll" DestinationFolder="C:\Program\bin" />
</Target>

Also I tried to debug it with simple <Message> instead of <Copy> with same result.

Is there a way to make it work in my .csproj.user?

1

There are 1 answers

0
Benny Bürger On

I stumbled across the same problem, after some experimentation the solution is quite easy:

<Target Name="UseAName" AfterTargets="Build">
    <Copy SourceFiles="$(ProjectDir)\$(OutputPath)\my.dll" DestinationFolder="C:\Program\bin" />
</Target>