我想删除一些图片资源,具体取决于我使用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...
可能甚至可以排除所有,然后只包括所需的那个?
答案 0 :(得分:9)
我已在http://sedodream.com/2010/08/15/WebDeploymentToolMSDeployHowToExcludeFilesFromPackageBasedOnConfiguration.aspx在我的博客上发布了一条关于此内容的条目。以下是摘要:
您使用与我之前的答案ExcludeFromPackageFiles相同的方法,但您只是在其上添加条件。因此,如果您在文件名中包含 scripts 文件夹下的'debug'文件,那么您希望从未在调试配置下构建的任何软件包中排除这些文件
<ItemGroup Condition=" '$(Configuration)'!='Debug' ">
<ExcludeFromPackageFiles Include="scripts\**\*debug*" />
</ItemGroup>
我博客上的更多细节,但它是上一种方法的简单模式。
答案 1 :(得分:5)
感谢您的回答。我现在修复了所有内容,在我的数据库(migrator.net)中包含构建和迁移的过程中遇到了很多困难,但我作弊并通过运行命令来完成。
我以为我在这里发布了整个部署过程,所以阅读这篇文章的人可能会从我的所有错误中吸取教训。 基本步骤是:
由<Import Project="Deploy.csproj" />
在webproject项目文件的最后一行导入的Deploy.proj:
<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=""..\MigratorProject\Bats\Client1.bat"" 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=""C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:contentPath="page of client1",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=""C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -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>
Backup.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
希望任何人都可以从此条目获得一些帮助和示例。
答案 2 :(得分:1)
您可以使用ItemGroup
上的Condition
属性和$(Configuration)
属性来扩展Sayed的示例。
e.g:
<ItemGroup>
<Content Include="a.jpeg" Condition=" '$(Configuration)' == 'Client1' " />
</ItemGroup>