【问题标题】:Web deployment: Exclude directories depending on Project Configuration nameWeb 部署:根据项目配置名称排除目录
【发布时间】:2010-08-14 19:57:39
【问题描述】:

我想删除一些图像资源,具体取决于我使用 MsDeploy 发布的版本。 我为不同的客户端构建了三个版本,它们基本上是另一个主题,并且进行了很多配置转换以正确设置他们的环境。

我不想在部署到 client2 时包含 client1 的图像资源。

一直在使用this as a reference 进行自定义 msdeploy 的第一步,它运行良好,但我不知道获取配置名称的变量是什么。

In pseudo code:
if $configurationName == "client1"
  exclude dirs gfx/client2 and gfx/client3
if $configurationName == "client2"
  exclude dirs gfx/client1, gfx/client3
and so on...

甚至可以排除所有然后只包含需要的那个?

【问题讨论】:

    标签: visual-studio-2010 msbuild web-deployment-project msdeploy


    【解决方案1】:

    我已在我的博客http://sedodream.com/2010/08/15/WebDeploymentToolMSDeployHowToExcludeFilesFromPackageBasedOnConfiguration.aspx 上发布了一篇关于此的文章。总结如下:

    您使用的方法与我之前的回答 ExcludeFromPackageFiles 中的方法相同,但您只是为其设置了一个条件。因此,如果您在 scripts 文件夹下有文件,文件名中包含 'debug',您希望从任何不是在调试配置下构建的包中排除,您的操作方式是

    <ItemGroup Condition=" '$(Configuration)'!='Debug' ">
      <ExcludeFromPackageFiles Include="scripts\**\*debug*" />
    </ItemGroup>
    

    我的博客上有更多详细信息,但它是对以前方法的简单修改。

    【讨论】:

      【解决方案2】:

      感谢您的回答。我现在修复了所有问题,在为我的数据库 (migrator.net) 包含构建和迁移方面付出了很多努力,但我作弊并通过 run 命令完成了。

      我想我在这里发布我的整个部署过程,以便阅读这篇文章的人可以从我的所有错误中吸取教训。 基本步骤是:

      • Web.config 转换以确保每个客户端的所有设置都正确
      • 在生产服务器上备份网络服务器文件和数据库
      • 排除所有客户端的所有 gfx 目录
      • 包括这个客户想要的 gfx 目录
      • 包括项目正确性未引用的额外二进制文件和许可证文件
      • 将数据库迁移到当前版本
      • Web 部署所有新文件

      Deploy.proj,由&lt;Import Project="Deploy.csproj" /&gt;在webproject项目文件最后一行导入:

      <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
          <PropertyGroup>
              <CopyAllFilesToSingleFolderForPackageDependsOn>
                  ExcludeAllGfx;
      
                  Client1Backup;
                  Client1Include;
                  Client1Migrate;
      
                  CollectBinFiles;
                  $(CopyAllFilesToSingleFolderForPackageDependsOn);
              </CopyAllFilesToSingleFolderForPackageDependsOn>
          </PropertyGroup>
      
          <Target Name="ExcludeAllGfx" BeforeTargets="ExcludeFilesFromPackage">
              <ItemGroup>
                  <ExcludeFromPackageFiles Include="gfx\client1\**\*.*">
                      <FromTarget>Project</FromTarget>
                  </ExcludeFromPackageFiles>
                  <ExcludeFromPackageFiles Include="gfx\client2\**\*.*">
                      <FromTarget>Project</FromTarget>
                  </ExcludeFromPackageFiles>
                  <ExcludeFromPackageFiles Include="gfx\client3\**\*.*">
                      <FromTarget>Project</FromTarget>
                  </ExcludeFromPackageFiles>
              </ItemGroup>
              <Message Text="ExcludeFromPackageFiles: @(ExcludeFromPackageFiles)" Importance="high" />
          </Target>
      
          <Target Name="CollectBinFiles">
              <ItemGroup>
                  <_CustomFiles Include="..\IncludeBin\Telerik\Telerik.ReportViewer.WebForms.dll" />
                  <_CustomFiles Include="..\IncludeBin\Telerik\Telerik.Reporting.dll" />
                  <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
                      <DestinationRelativePath>Bin\%(Filename)%(Extension)</DestinationRelativePath>
                  </FilesForPackagingFromProject>
              </ItemGroup>
          </Target>
      
          <Target Name="Client1Migrate" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'">
              <Exec Command="&quot;..\MigratorProject\Bats\Client1.bat&quot;" ContinueOnError="false" />
          </Target>
      
          <Target Name="Client1Include" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'">
              <ItemGroup>
                  <_CustomFilesClient1 Include="gfx\Client1\**\*.*" Exclude="gfx\Client1\**\.svn\**\*.*">
                      <FromTarget>Project</FromTarget>
                  </_CustomFilesClient1>
                  <FilesForPackagingFromProject Include="%(_CustomFilesClient1.Identity)">
                      <DestinationRelativePath>gfx\client1\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
                  </FilesForPackagingFromProject>
              </ItemGroup>
          </Target>
      
          <Target Name="Client1Backup" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'">
              <Exec Command="&quot;C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe&quot; -verb:sync -source:contentPath=&quot;page of client1&quot;,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass -dest:package=c:\Backups\deployments\client1.zip,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass" ContinueOnError="false" />
              <Exec Command="&quot;C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe&quot; -verb:sync -source:runCommand='C:\Backups\deployments\scripts\backup.cmd client1',waitInterval=20000 -dest:auto,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass" ContinueOnError="false" />
          </Target>
      </Project>
      

      备份.cmd:

      @echo off
      sqlcmd -v name=%1 -S . -i "C:\Backups\deployments\scripts\backupdb.sql"
      C:\Backups\deployments\scripts\stampme "C:\Backups\deployments\%1.zip"
      

      backupdb.sql:

      DECLARE @name NVARCHAR(50) -- database name 
      DECLARE @path NVARCHAR(256) -- path for backup files 
      DECLARE @fileName NVARCHAR(256) -- filename for backup 
      DECLARE @fileDate NVARCHAR(20) -- used for file name 
      
      SET @name = '$(name)'
      SET @path = 'C:\Backups\deployments\' 
      SELECT @fileDate = REPLACE(REPLACE(CONVERT(VARCHAR(50),GETDATE(),120),':','-'), ' ', '@')
      SET @fileName = @path + @name + '_' + @fileDate + '.BAK' 
      BACKUP DATABASE @name TO DISK = @fileName;
      

      stampme.bat:http://ss64.com/nt/syntax-stampme.html

      希望任何人都能从这篇文章中得到一些帮助和例子。

      【讨论】:

      • "包括项目正确性未引用的额外二进制文件和许可证文件" -> 只需将它们添加到项目集中以复制到输出。
      • 是的,但是开发机器和登台/生产服务器的许可证不同,这就是为什么我什至不希望它们出现在项目中。
      【解决方案3】:

      您可以使用ItemGroup 上的Condition 属性和$(Configuration) 属性来扩展Sayed 的示例。

      例如:

      <ItemGroup>
          <Content Include="a.jpeg" Condition=" '$(Configuration)' == 'Client1' " />
      </ItemGroup>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-17
        • 1970-01-01
        • 2015-04-18
        • 1970-01-01
        • 2015-09-26
        • 2012-07-18
        • 1970-01-01
        • 2013-08-07
        相关资源
        最近更新 更多