1

I have a web application (WebAPI web service) that is building on my CI server. It builds and publishes fine using VS2013, a publish to file system publish profile (*.pubxml) and the below command from the CI server task.

MSBuild %ProjectPath%/MyApp.sln /t:Clean,Build /p:Configuration=Release;DeployOnBuild=True;PublishProfile=TAGBIN;VisualStudioVersion=12.0

However I also need to obfuscate the software, the obfuscator (Red Gate Smart Assembly), is invoked via the below xml placed inside the csproj file.

<UsingTask TaskName="SmartAssembly.MSBuild.Tasks.Build" AssemblyName="SmartAssembly.MSBuild.Tasks, Version=6.0.0.0,&#xD;&#xA;Culture=neutral, PublicKeyToken=7f465a1c156d4d57" />
<Target Name="PostBuildEvent" Condition=" '$(Configuration)' == 'Release' ">
    <SmartAssembly.MSBuild.Tasks.Build ProjectFile="MyApp.saproj" />
</Target>

This appears to build and publish fine, however upon inspecting the command line output I have noticed that the publish occurs before the obfuscation.

Obviously obfuscation needs to happen after the build, but before the publish, is this possible?

I have tried a few things, including editing the *.pub.xml file to call obfuscate via a 'BuildDependsOn' node, but this causes the obfuscation to run before the build.

<BuildDependsOn>        
    Obfuscate;
    $(BuildDependsOn);
</BuildDependsOn>

It just does not seem possible to decouple the build from the publish, the only option I have at the moment is to build it twice, where the second publish picks up the obfuscated files from the first build.

RobJohnson
  • 875
  • 11
  • 21
  • Your incremental build is badly broken. The reason is your `SmartAssembly` task overwrites the file that was produced in previous build step in-place. The logic of incremental build is based on file timestamps, so you will see weird build behaviour building and re-building your project. I suggest you start by properly defining the Target, by separating inputs from outputs, and specifying `Inputs` and `Outputs` attributes on Target element. – seva titov Apr 05 '15 at 18:00
  • The Smart Assembly task actually puts the obfuscated executables in a separate folder and I configure the publish to take the files from this 'Obfuscated' folder. The problem I have is that the publish happens before the obfuscation, therefore there aren't yet any obfuscated files to publish. I just want to know how to get the publish to happen after obfuscation. – RobJohnson Apr 07 '15 at 08:09
  • You wrote that "This appears to build and publish fine", which implies that the publish step found binaries from your reconfigured location with obfuscated binaries. If the original binaries created by CSC are not overrwitten by your custom step, then you should be fine. The ordering in MSBuild is easy, just use attributes `BeforeTargets` and/or `AfterTargets`. – seva titov Apr 07 '15 at 16:13

1 Answers1

1

In MSBuild 4.0 and above you can use BeforeTargets and AfterTargets to control target build order.

Example below introduces new build step that executes after build but before publishing:

<Target Name="MyNewBuildStep" AfterTargets="CoreBuild" BeforeTargets="Publish">
    <Message Text="Executing new build step" />
</Target>
seva titov
  • 11,720
  • 2
  • 35
  • 54