Set Up Virtual Directories From The Build
Following up my previous post, an approach to extending msbuild, here’s what we ended up using to setup out web sites and services. We have a very service oriented architecture here and are starting to have a lot of web services that need to be setup before any testing or debugging can take place.
The build file takes some arguments about the location of the CS project file and the name of the Virtual Directory to setup. Currently, we’re only handling virtual directories, but going forward, we like to handle everything needed to get the system up and running an a local machine. Anyway, the file is checking for extension points in the build file using and XML read on the existing build target. This is because msbuild, as far as I could find, doesn’t have a target exists method. I thinking about removing these check, as I don’t think we’re going to end up using them like I initially thought.
However, the bulk of the file is in the **AspNetSetup target. It checks for a default IIS 6 web site and if found it deletes any existing virtual directory and re-creates it. This helps if you have different branches in different locations and want to quickly change the setup.
Anyway, here’s the XML:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CopyToOutput">
<PropertyGroup>
<MSBuildCommunityPackPath>....\ThirdParty.Dependencies\MSBuild.Community.TasksMSBuildCommunityPackPath>
<MSBuildCommunityTasksPath>.MSBuildCommunityTasksPath>
PropertyGroup>
<Import Project="$(MSBuildCommunityPackPath)\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<MSBuildExtensionPackPath>....\ThirdParty.Dependencies\MSBuild Extension\ExtensionPackMSBuildExtensionPackPath>
<ExtensionTasksPath>.ExtensionTasksPath>
PropertyGroup>
<Import Project="$(MSBuildExtensionPackPath)\MSBuild.ExtensionPack.tasks"/>
<Import Project="$(ProjectFile)" Condition="$(ProjectFile) != ‘’"/>
<ItemGroup>
<ProjectPath Include="$(ProjectFile)">ProjectPath>
ItemGroup>
<PropertyGroup>
<SetupDependsOnTargets>CoreBeforeSetup;CoreAspNetSetup;CoreAfterSetupSetupDependsOnTargets>
PropertyGroup>
<Target Name="Setup" DependsOnTargets="$(SetupDependsOnTargets)">
Target>
<Target Name="CoreBeforeSetup">
<Message Text="Setup: $(ProjectFile) types ‘$(ProjectTypeGuids)’" Importance="high" />
<XmlRead Prefix="n"
Namespace="http://schemas.microsoft.com/developer/msbuild/2003"
XPath="/n:Project/n:Target[@Name=‘BeforeSetup’]/@Name"
XmlFileName="$(ProjectFile)">
<Output TaskParameter="Value" PropertyName="FoundTargetName" />
XmlRead>
<CallTarget Targets="BeforeSetup" Condition="$(FoundTargetName) != ‘’" />
Target>
<Target Name="InitializeCoreAspNetSetup" Condition="‘@(AspNetWebsiteDirectories)’ == ‘’">
<CreateItem
Include="%(ProjectPath.RootDir)%(ProjectPath.Directory)"
AdditionalMetadata="IISVirtualDirectory=$(IISVirtualDirectory)"
Condition="Exists(‘$(OutputDirectory)$(AssemblyName)’) AND ‘$(IISVirtualDirectory)’ != ‘’">
<Output TaskParameter="Include" ItemName="AspNetWebsiteDirectories" />
CreateItem>
Target>
<Target Name="CoreAspNetSetup"
DependsOnTargets="InitializeCoreAspNetSetup">
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">CallTarget</span><span style="color: blue"> </span><span style="color: red">Targets</span><span style="color: blue">=</span>"<span style="color: blue"></strong>AspNetSetup</span>"<span style="color: blue"> </span><span style="color: red">Condition</span><span style="color: blue">=</span>"<span style="color: blue">‘@(AspNetWebsiteDirectories)’ != ‘’</span>"<span style="color: blue">/></span>
</p>
<p style="margin: 0px">
<span style="color: blue">    </</span><span style="color: #a31515">Target</span><span style="color: blue">></span>
</p>
<p style="margin: 0px">
 
</p>
<p style="margin: 0px">
<span style="color: blue">    <</span><span style="color: #a31515">Target</span><span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>"<span style="color: blue">__AspNetSetup</span>"<span style="color: blue">></span>
</p>
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">Iis6Website</span><span style="color: blue"> </span><span style="color: red">TaskAction</span><span style="color: blue">=</span>"<span style="color: blue">CheckExists</span>"<span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>"<span style="color: blue">Default Web Site</span>"<span style="color: blue"> ></span>
</p>
<p style="margin: 0px">
<span style="color: blue">            <</span><span style="color: #a31515">Output</span><span style="color: blue"> </span><span style="color: red">PropertyName</span><span style="color: blue">=</span>"<span style="color: blue">Iis6Exists</span>"<span style="color: blue"> </span><span style="color: red">TaskParameter</span><span style="color: blue">=</span>"<span style="color: blue">Exists</span>"<span style="color: blue">/></span>
</p>
<p style="margin: 0px">
<span style="color: blue">        </</span><span style="color: #a31515">Iis6Website</span><span style="color: blue">></span>
</p>
<p style="margin: 0px">
 
</p>
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">Message</span><span style="color: blue"> </span><span style="color: red">Text</span><span style="color: blue">=</span>"<span style="color: blue">Website: %(AspNetWebsiteDirectories.IISVirtualDirectory) At %(AspNetWebsiteDirectories.FullPath)</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                 </span><span style="color: red">Importance</span><span style="color: blue">=</span>"<span style="color: blue">high</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                 </span><span style="color: red">Condition</span><span style="color: blue">=</span>"<span style="color: blue">$(Iis6Exists)</span>"<span style="color: blue">/></span>
</p>
<p style="margin: 0px">
 
</p>
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">WebDirectoryDelete</span><span style="color: blue"> </span><span style="color: red">VirtualDirectoryName</span><span style="color: blue">=</span>"<span style="color: blue">%(AspNetWebsiteDirectories.IISVirtualDirectory)</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                            </span><span style="color: red">ContinueOnError</span><span style="color: blue">=</span>"<span style="color: blue">true</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                            </span><span style="color: red">Condition</span><span style="color: blue">=</span>"<span style="color: blue">$(Iis6Exists)</span>"<span style="color: blue">/></span>
</p>
<p style="margin: 0px">
 
</p>
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">WebDirectoryCreate</span><span style="color: blue"> </span><span style="color: red">VirtualDirectoryName</span><span style="color: blue">=</span>"<span style="color: blue">%(AspNetWebsiteDirectories.IISVirtualDirectory)</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                            </span><span style="color: red">VirtualDirectoryPhysicalPath</span><span style="color: blue">=</span>"<span style="color: blue">%(AspNetWebsiteDirectories.FullPath)</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                            </span><span style="color: red">Condition</span><span style="color: blue">=</span>"<span style="color: blue">$(Iis6Exists)</span>"<span style="color: blue">/></span>
</p>
<p style="margin: 0px">
<span style="color: blue">    </</span><span style="color: #a31515">Target</span><span style="color: blue">></span>
</p>
<p style="margin: 0px">
 
</p>
<p style="margin: 0px">
<span style="color: blue">    <</span><span style="color: #a31515">Target</span><span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>"<span style="color: blue">CoreAfterSetup</span>"<span style="color: blue">></span>
</p>
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">XmlRead</span><span style="color: blue"> </span><span style="color: red">Prefix</span><span style="color: blue">=</span>"<span style="color: blue">n</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                 </span><span style="color: red">Namespace</span><span style="color: blue">=</span>"<span style="color: blue">http://schemas.microsoft.com/developer/msbuild/2003</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                 </span><span style="color: red">XPath</span><span style="color: blue">=</span>"<span style="color: blue">/n:Project/n:Target[@Name=‘AfterSetup’]/@Name</span>"
</p>
<p style="margin: 0px">
<span style="color: blue">                 </span><span style="color: red">XmlFileName</span><span style="color: blue">=</span>"<span style="color: blue">$(ProjectFile)</span>"<span style="color: blue">></span>
</p>
<p style="margin: 0px">
<span style="color: blue">            <</span><span style="color: #a31515">Output</span><span style="color: blue"> </span><span style="color: red">TaskParameter</span><span style="color: blue">=</span>"<span style="color: blue">Value</span>"<span style="color: blue"> </span><span style="color: red">PropertyName</span><span style="color: blue">=</span>"<span style="color: blue">FoundTargetName</span>"<span style="color: blue"> /></span>
</p>
<p style="margin: 0px">
<span style="color: blue">        </</span><span style="color: #a31515">XmlRead</span><span style="color: blue">></span>
</p>
<p style="margin: 0px">
<span style="color: blue">        <</span><span style="color: #a31515">CallTarget</span><span style="color: blue"> </span><span style="color: red">Targets</span><span style="color: blue">=</span>"<span style="color: blue">AfterSetup</span>"<span style="color: blue"> </span><span style="color: red">Condition</span><span style="color: blue">=</span>"<span style="color: blue">$(FoundTargetName) != ‘’</span>"<span style="color: blue"> /></span>
</p>
<p style="margin: 0px">
<span style="color: blue">    </</span><span style="color: #a31515">Target</span><span style="color: blue">></span>
</p>
<p style="margin: 0px">
<span style="color: blue"></</span><span style="color: #a31515">Project</span><span style="color: blue">></span>
</p></p></div></p>
Webmentions
These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: