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

Set Up Virtual Directories From The Build

Dusty Candland | |

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">

        <CallTarget Targets="AspNetSetup" Condition="‘@(AspNetWebsiteDirectories)’ != ‘’"/>

    </Target>

 

    <Target Name="__AspNetSetup">

        <Iis6Website TaskAction="CheckExists" Name="Default Web Site" >

            <Output PropertyName="Iis6Exists" TaskParameter="Exists"/>

        </Iis6Website>

 

        <Message Text="Website: %(AspNetWebsiteDirectories.IISVirtualDirectory) At %(AspNetWebsiteDirectories.FullPath)"

                 Importance="high"

                 Condition="$(Iis6Exists)"/>

 

        <WebDirectoryDelete VirtualDirectoryName="%(AspNetWebsiteDirectories.IISVirtualDirectory)"

                            ContinueOnError="true"

                            Condition="$(Iis6Exists)"/>

 

        <WebDirectoryCreate VirtualDirectoryName="%(AspNetWebsiteDirectories.IISVirtualDirectory)"

                            VirtualDirectoryPhysicalPath="%(AspNetWebsiteDirectories.FullPath)"

                            Condition="$(Iis6Exists)"/>

    </Target>

 

    <Target Name="CoreAfterSetup">

        <XmlRead Prefix="n"

                 Namespace="http://schemas.microsoft.com/developer/msbuild/2003"

                 XPath="/n:Project/n:Target[@Name=‘AfterSetup’]/@Name"

                 XmlFileName="$(ProjectFile)">

            <Output TaskParameter="Value" PropertyName="FoundTargetName" />

        </XmlRead>

        <CallTarget Targets="AfterSetup" Condition="$(FoundTargetName) != ‘’" />

    </Target>

</Project>

Webmentions

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