IIS web deploy - create virtual directories?
Asked Answered
T

3

7

When developing a site on VS2010/IIS 7.5, I'm using Web Deploy to publish the site from my machine to the dev site server.

The site has about 40 virtual directories, and I'd like to automagically create those on the server during the deployment. Is there a simple way to do this?

I'm considering writing a small app that would load the list from a file or database and create them on demand. The directories have different physical paths on my development machine than on the web server, also, which throws a wrench into the works.

Taipan answered 19/11, 2010 at 20:37 Comment(2)
40 virtual directories? So you have 40 different applications. Hmmm, that seems like a lot. What kind of site are you developing? I know small hosting providers that have less virtual directories on their server than you :-)Chitter
No, it's not 40 different apps. I'm gradually migrating a HUGE (400k+lines of code and over 100,000 pages) classic ASP app to .NET MVC. The virt folders let the new site access the old content at existing urls.Taipan
M
6

If you're using MSBuild for your web deploy you can write a CustomBuildTask in .net that you can use to create your virtual directory.

There are a lot of resources on how to create and consume a custom build task, but here is the code I use to create a virtual directory using a custom build task:

public void CreateVirtualDirectory()
{

    DirectoryEntry oDE = new DirectoryEntry("IIS://" +
            this._strServerName + "/W3SVC/" + _webSiteID + "/Root");


    //Get Default Web Site
    DirectoryEntries oDC = oDE.Children;

    //Add row to schema
    DirectoryEntry oVirDir = oDC.Add(this._strVDirName,
                oDE.SchemaClassName.ToString());

    //Commit changes for Schema class File
    oVirDir.CommitChanges();


    //Set virtual directory to physical path
    oVirDir.Properties["Path"].Value = this._strPhysicalPath;

    //Set read access
    oVirDir.Properties["AccessRead"][0] = true;

    //Set the default docs
    oVirDir.Properties["EnableDefaultDoc"][0] = true;
    oVirDir.Properties["DefaultDoc"][0] = "default.aspx";

    //set the name
    oVirDir.Properties["AppFriendlyName"][0] = this._strVDirName;

    //do it
    oVirDir.Invoke("AppCreate", true);


    //set the application pool
    if (!string.IsNullOrEmpty(_strApplicationPool))
    {
        object[] param = { 0, _strApplicationPool, true };
        oVirDir.Invoke("AppCreate3", param);
        oVirDir.Properties["AppIsolated"][0] = "2";
    }

    //Save all the changes
    oVirDir.CommitChanges();
}
Mixon answered 19/11, 2010 at 21:19 Comment(2)
Thanks for the code sample. I was (of course) hoping for something that would be a bit more automated, but this will certainly get the job done.Taipan
How would this get run if I'm executing the msbuild with publish command? I can't see any relation between it and the publishing profile. Could you elaborate more?Boloney
F
1

I've not done any custom programming against WebDeploy, but I've seen reference that there is an API for it. I can't seem to find official documentation on it, but perhaps this blog+sample app could provide a start: Web Deploy API Web Application

Finegan answered 19/11, 2010 at 20:52 Comment(0)
C
0

Could you please share your solution? I'm deploying an asp.net webforms application to IIS using WebDeploy and I have to create 02 virtual directories (pointing to different drives) that hold .pdf files.

How Do I hook the CustomBuildTask that AaronS pointed on my .pubxml file? .Below is a snippet of the file.

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>https://www.myapplication.com/app</SiteUrlToLaunchAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>www.myapplication.com</MSDeployServiceURL>
    <DeployIisAppPath>Default Web Site/app</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>administrator</UserName>
    <_SavePWD>True</_SavePWD>
    <PublishDatabaseSettings>
        <!-- ... -->
    </PublishDatabaseSettings>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)SiteConnectionString-Web.config Connection String" />
  </ItemGroup>
</Project>

IIS should have the pdfmedia virtual directory after I publish the application from Visual Studio 2019.

pdfmedia

Thank you very much!

Cana answered 1/4, 2021 at 20:24 Comment(3)
I'd love to help, but I left that company many years ago and don't have access to that project anymore (and I haven't touched a web app since ~2016). I'd suggest posting this as a new question.Taipan
this answer is not really an answer and should be posted as a comment insteadForesheet
My reputation didn't allow me to post commentsCana

© 2022 - 2024 — McMap. All rights reserved.