Msbuild:如何创建虚拟目录

时间:2013-02-25 04:43:42

标签: asp.net msbuild

我是MSBuild的新手。我需要在IIS中创建一个虚拟目录但我不知道如何不尝试一些教程,但是它们是如此模糊,所以请指导我,我的当前代码如下所示

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
  <PropertyGroup>
    <Resource >D:\test_2\Tony_Mail\Tony_Mail\Tony_Mail.csproj</Resource>
    <OutputDir>D:\test_2\Tony_Mail\Tony_Mail\Build</OutputDir>
    <clean>D:\test_2\Tony_Mail\Tony_Mail\Build\bin\*.pdb</clean>

  </PropertyGroup>
  <Target Name="Build">
    <MSBuild Projects="D:\test_2\Tony_Mail\Tony_Mail\Tony_Mail.csproj"></MSBuild>
    <CallTarget Targets="Publish"></CallTarget>
  </Target>
  <Target Name="Publish">
    <MSBuild Projects="$(Resource)" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=S(OutputDir);OutDir=$(MSBuildProjectsDirectory)\Bin\"></MSBuild>
    <CallTarget Targets="Clean"></CallTarget>
  </Target>

  <Target Name="Clean">
    <Delete Files="$(clean)" />
  </Target>

</Project>

1 个答案:

答案 0 :(得分:3)

使用以下代码

<WebDirectoryCreate VirtualDirectoryName="MyVirDir"
     VirtualDirectoryPhysicalPath="C:\Inetpub\MyWebDir" />

并在创建之前添加删除代码,否则会导致错误,使用以下代码

<WebDirectoryDelete VirtualDirectoryName="MyVirDir" />

所以完整的代码块将是这样的

<Target Name="VirtualDirectory">
    <WebDirectoryDelete VirtualDirectoryName="MyVirDir" />
    <WebDirectoryCreate VirtualDirectoryName="MyVirDir"
        VirtualDirectoryPhysicalPath="C:\Inetpub\MyWebDir" />
</Target>