Profile picture Schedule a Meeting
c a n d l a n d . n e t

An Approach to Extending MSBuild

Dusty Candland | |

download

I’m working toward setting up a master build for our enterprise code using MSBuild. My first pass was to include a common build project in each of our csproj files. This was a bad idea for two reasons. One it’s a pain to update each csproj file. And two, VS complains when you open a csproj file with modifications. So, it was off to find a different approach, this was inspired by Sayed Ibrahim. The idea is to call your common build project file with the csproj file name and import that, giving you access to that files properties. One issue is the relative paths are now based on your common build projects location, this didn’t end up being to much of an issue. So anyway, here some code … err XML:

    <Target Name="CoreDeploy" DependsOnTargets="CoreBuild">

        <MSBuild Projects="SubProjects\Publish.proj" Targets="Deploy"

                 Properties="ProjectFile=%(ProjectsToBuild.FullPath);OutputDirectory=$(OutputRootDirectory);IISVirtualDirectory=%(ProjectsToBuild.IISVirtualDirectory)">

        MSBuild>

    Target>

The above calls into the Publish.proj file, which in turn includes the passed in ProjectFile.

 

    <Import Project="$(ProjectFile)" Condition="$(ProjectFile)!=‘’"/>

    <ItemGroup>

        <ProjectPath Include="$(ProjectFile)">ProjectPath>

    ItemGroup>

The above bit of code includes the project file in the Deploy.proj allowing it’s targets, properties, and items to be called.

Using the above approach I could have common setup project and a common deploy project, I’ll blog about these in following posts.

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: