Fervent Coder

Coding Towards Utopia...by Rob Reynolds
posts - 278 , comments - 431 , trackbacks - 0

My Links

News


Rob Reynolds

Subscribe to Fervent Coder RSS
Subscribe to Fervent Coder by Email

About Me

I manage several open source projects. Need...
   ...package management for Windows?
   ...automated builds?
   ...database change management (migrations)?
   ...your application to check email?
   ...a monitoring utility?

I also write for



Like what you are reading? Want to buy me a cup of coffee?
PayPal - The safer, easier way to pay online!

Archives

Post Categories

Image Galleries

Sites

Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

From my previous post of WebDirectoryCreate I have an example script of how you would use MSBuild Community Tasks to Set up Virtual Directories and/or do updates to the current virtual directory.

The below is an example of how you can create or update virtual directories.  This is what you would add to the MSBuild.proj file.

 

<PropertyGroup>
  <!-- Virtual Directory Items-->
  <EnableVirtualDirectorySetup>True</EnableVirtualDirectorySetup>
  <VirtualDirectoryApplicationPoolName>ASPNET2</VirtualDirectoryApplicationPoolName>
  <!-- Main App Virtual Directory -->
  <VirtualDirectoryPath></VirtualDirectoryPath>
  <VirtualDirectoryName>ZVirDir</VirtualDirectoryName>
  <VirtualDirectoryFullName>$(VirtualDirectoryPath)$(VirtualDirectoryName)</VirtualDirectoryFullName>
  <VirtualDirectoryDefaultDoc>default.aspx</VirtualDirectoryDefaultDoc>
  <EnableVirtualDirectoryAnonymousAccess>true</EnableVirtualDirectoryAnonymousAccess>
</PropertyGroup>
 
<Choose>
  <When Condition=" '$(Environment)'=='DEV' ">
    <PropertyGroup>
      <WebAppServer>serverDev</WebAppServer>
      <!-- Main App Virtual Directory -->
      <VirtualDirectorySetupServerName>$(WebAppServer)</VirtualDirectorySetupServerName>
      <VirtualDirectoryHostHeader>OrgDev</VirtualDirectoryHostHeader>
      <VirtualDirectoryPath>dude/</VirtualDirectoryPath>
      <VirtualDirectoryFullName>$(VirtualDirectoryPath)$(VirtualDirectoryName)</VirtualDirectoryFullName>
      <VirtualDirectoryPhysicalPath>E:\Dev\$(VirtualDirectoryName)</VirtualDirectoryPhysicalPath>
    </PropertyGroup>
  </When>
  <When Condition=" '$(Environment)'=='TEST' ">
    <PropertyGroup>
      <WebAppServer>serverTest</WebAppServer>
      <!-- Main App Virtual Directory -->
      <VirtualDirectorySetupServerName>$(WebAppServer)</VirtualDirectorySetupServerName>
      <VirtualDirectoryHostHeader>test.com</VirtualDirectoryHostHeader>
      <VirtualDirectoryPhysicalPath>E:\Code\$(VirtualDirectoryName)</VirtualDirectoryPhysicalPath>
    </PropertyGroup>
  </When>
</Choose>
 
<Target Name="AppVirtualDirectoryDeploy" Condition="$(EnableVirtualDirectorySetup) =='true'">
 
    <!-- Virtual Directory Setup -->
    <Message Text="" />
    <Message Text="" />
    <Message Text="**********************************************" />
    <Message Text="Virtual Directory/Web.Config Setup - $(Environment)" />
    <Message Text="**********************************************" />
    <Message Text="" />
 
 
    <AppPoolCreate
        Condition="$(Environment) !='LOCAL' AND $(VirtualDirectoryApplicationPoolName) !=''"
        ServerName="$(VirtualDirectorySetupServerName)"
        ApplicationPoolName="$(VirtualDirectoryApplicationPoolName)"
        ContinueOnError="true"
        />
 
    <!-- Virtual Directory Setup - Web Deploy -->
 
    <Message Text="" />
    <Message Text="" />
    <Message Text="**********************************************" />
    <Message Text="Virtual Directory Creation for $(VirtualDirectoryFullName) - $(Environment)" />
    <Message Text="**********************************************" />
    <Message Text="" />
 
    <Message
        Condition="$(Interactive) != 'true'"
        Text="|| Skipping - Interactive setup must be enabled ||"
        />
 
    <Prompt
        Condition="$(Interactive) == 'true'"
        Text="Create virtual directory (leave blank for No)?"
        >
      <Output TaskParameter="UserInput" PropertyName="CreateWebDirectory"/>
    </Prompt>
 
    <!--<WebDirectoryDelete
      Condition="$(CreateWebDirectory) !='' AND $(CreateWebDirectory) !='N'"
      ServerName="$(VirtualDirectorySetupServerName)"
      HostHeaderName="$(VirtualDirectoryHostHeader)"
      VirtualDirectoryName="$(VirtualDirectoryFullName)"
      ContinueOnError="true"
        />-->
 
    <WebDirectoryCreate
        Condition="$(CreateWebDirectory) !='' AND $(CreateWebDirectory) !='N'"
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        VirtualDirectoryPhysicalPath="$(VirtualDirectoryPhysicalPath)"
        AccessRead="True"
        AuthAnonymous="$(EnableVirtualDirectoryAnonymousAccess)"
        AnonymousPasswordSync="False"
        AuthNtlm="True"
        EnableDefaultDoc="True"
        ContinueOnError="true"
        />
 
 
    <Message Text="" />
    <Message Text="" />
    <Message Text="**********************************************" />
    <Message Text="Virtual Directory Updates for $(VirtualDirectoryFullName) - $(Environment)" />
    <Message Text="**********************************************" />
    <Message Text="" />
 
    <WebDirectoryScriptMap
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        Extension=".svc"
        MapToAspNet="True"
        VerifyFileExists="False"
        Verbs="GET,POST,HEAD,DEBUG"
        />
 
    <WebDirectorySetting
        Condition="$(VirtualDirectoryDefaultDoc) !=''"
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        SettingName="DefaultDoc"
        SettingValue="$(VirtualDirectoryDefaultDoc)"
        />
 
    <WebDirectorySetting
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        SettingName="AppFriendlyName"
        SettingValue="$(VirtualDirectoryName)"
        />
 
    <WebDirectorySetting
        Condition="$(Environment) !='LOCAL' AND $(VirtualDirectoryApplicationPoolName) !=''"
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        SettingName="AppPoolId"
        SettingValue="$(VirtualDirectoryApplicationPoolName)"
        ContinueOnError="true"
        />
 
    <Message Text="" />
    <Message Text="" />
    <Message Text="**********************************************" />
    <Message Text="Virtual Directory Anonymous Authorization Account for $(VirtualDirectoryFullName) - $(Environment)" />
    <Message Text="**********************************************" />
    <Message Text="" />
 
    <Message
        Condition="$(Interactive) != 'true' OR $(EnableVirtualDirectoryAnonymousAccess) !='true'"
        Text="|| Skipping - Anonymous authentication and interactive setup must be enabled ||"
        />
 
    <Prompt
        Condition="$(EnableVirtualDirectoryAnonymousAccess) =='true' AND $(Interactive) == 'true'"
        Text="What is the Domain\UserName for the anonymous account (leave blank for inherited/current)?"
        >
      <Output TaskParameter="UserInput" PropertyName="VirtualDirectoryAnonymousUserName"/>
    </Prompt>
    <Message Text="" />
    <Prompt
        Condition="$(VirtualDirectoryAnonymousUserName)!=''"
        Text="Password:"
        >
      <Output TaskParameter="UserInput" PropertyName="VirtualDirectoryAnonymousPassword"/>
    </Prompt>
 
    <WebDirectorySetting
        Condition="$(VirtualDirectoryAnonymousUserName)!=''"
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        SettingName="AnonymousUserName"
        SettingValue="$(VirtualDirectoryAnonymousUserName)"
        />
 
    <WebDirectorySetting
        Condition="$(VirtualDirectoryAnonymousUserName)!=''"
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        SettingName="AnonymousPasswordSync"
        SettingValue="false"
        />
 
    <WebDirectorySetting
        Condition="$(VirtualDirectoryAnonymousUserName)!=''"
        ServerName="$(VirtualDirectorySetupServerName)"
        HostHeaderName="$(VirtualDirectoryHostHeader)"
        VirtualDirectoryName="$(VirtualDirectoryFullName)"
        SettingName="AnonymousUserPass"
        SettingValue="$(VirtualDirectoryAnonymousPassword)"
        />
 
</Target>

Print | posted on Tuesday, December 18, 2007 11:49 PM | Filed Under [ Code ]

Feedback

Gravatar

# re: Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

This is really useful example. Thank-you

It is great to see others incorporating the deployment process in the build process....
9/19/2008 10:51 AM | jamesb
Gravatar

# re: Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

@jamesb: It looks like it finally got rolled into MSBuild Community Tasks.
9/20/2008 9:49 AM | Robz
Gravatar

#  Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

Of course this post is interesting.

But when I tried to implement it on my machine(or in the network, I tried many different ways) MSBuid always gives me the same error:"Web directory "DirName" does not exist on localhost"

Instead parameter "DirName" I tried insert almost everything:
1 dirname
2 c:\dir1\dir2\dirname
3 /LM/W3SVC/1/ROOT
4 . . . .

And there were many other attepmts ((((

Now I'm interested in values of you parameters $(VirtualDirectoryFullName) and $(VirtualDirectoryPath)
1/14/2009 11:15 AM | walash
Gravatar

# re: Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

@walash: The virtual directory name is a relative path that is based on what the url looks like: http://localhost/temp/appdirectory


<VirtualDirectoryPath>temp/</VirtualDirectoryPath> <VirtualDirectoryName>appdirectory</VirtualDirectoryName> <VirtualDirectoryFullName>$(VirtualDirectoryPath)$(VirtualDirectoryName)</VirtualDirectoryFullName>
1/14/2009 4:33 PM | Robz
Gravatar

# Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

Thanks for your answer but it still doesn't work. The pathes that I tried to use last time:

1 http://localhost/temp/appdirectory
2 temp/appdirectory
3 appdirectory

But nothing helps.

And one more question. I deploy my web site to remote machine, that is why it is neccessaty to copy new files on it. This some code example how I do it now:

<ItemGroup>
<App_Code Include="$(SyncServicePath)\App_Code\*.*" />
<App_WebReferences Include="$(SyncServicePath)\App_WebReferences\TimeReportingService\*.*" />
<Bin Include="$(SyncServicePath)\Bin\*.*" />
<Events Include="$(SyncServicePath)\App_Code\Events\*.*" />
<Services Include="$(SyncServicePath)\App_Code\Services\*.*" />
<Root Include="$(SyncServicePath)\*.*" />
</ItemGroup>

. . . . . .

<Target Name="CopyFiles" Condition="'$(ComputerName)'!='$(SyncServiceMachineName)'" >
<Copy
SourceFiles="@(App_Code)"
DestinationFolder="$(Destination)\App_Code"
ContinueOnError="false"
/>
<Copy
SourceFiles="@(App_WebReferences)"
DestinationFolder="$(Destination)\App_WebReferences\TimeReportingService"
ContinueOnError="false"
/>
<Copy
SourceFiles="@(Bin)"
DestinationFolder="$(Destination)\Bin"
ContinueOnError="false"
/>
<Copy
SourceFiles="@(Events)"
DestinationFolder="$(Destination)\App_Code\Events\"
ContinueOnError="false"
/>
<Copy
SourceFiles="@(Services)"
DestinationFolder="$(Destination)\App_Code\Services"
ContinueOnError="false"
/>
<Copy
SourceFiles="@(Root)"
DestinationFolder="$(Destination)"
ContinueOnError="false"
/>
</Target>

So I try to save folder hierarchy and I must to write many strings of similar code. May be you can give me advice how can I do this in other way.
1/15/2009 6:02 AM | walash
Gravatar

# Automated Deployment - MSBuild.Community.Tasks - WebDirectoryCreate / WebDirectorySettings Example

Oh, I found the answer to the second part of my question. If we want to copy folder with all subfolders and files we can use code like this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
<MySourceFiles Include="c:\MySourceTree\**\*.*"/>
</ItemGroup>

<Target Name="CopyFiles">
<Copy
SourceFiles="@(MySourceFiles)"
DestinationFiles="@(MySourceFiles->'c:\MyDestinationTree\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>

</Project>

(example from MSDN © )
1/15/2009 6:59 AM | walash
Comments have been closed on this topic.

Powered by: