在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则

我正在尝试使用WebDeploy发布使用自定义MSDeploy跳过规则和保存在Visual Studio 2012中的发布configuration文件的网站。

我的发布configuration文件从命令行工作,但跳过规则跳过删除文件夹不起作用。

我在我的web应用程序中有一个ErrorLog子文件夹,里面有一个web.config文件来设置正确的文件夹权限。 如果没有任何跳过规则, ErrorLog文件夹和web.config文件将正常发布,但在发布时将删除服务器上文件夹中的所有现有错误日志文件。


<SkipAction>Delete</SkipAction>

当我将自定义跳过规则添加到我的wpp.targets文件时,跳过规则不再接受<SkipAction>元素的值。 如果我设置了<SkipAction>Delete</SkipAction> ,我得到以下错误:

 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4377,5): error : Web deployment task failed. (Unrecognized skip directive 'skipaction'. Must be one of the following: "objectName," "keyAttribute," "absolutePath," "xPath," "attributes.<name>.") [C:\inetpub\wwwroot\My.Website\My.Website\My.Website.csproj] 

如果我简单地省略<SkipAction>元素, ErrorLog文件夹将在正常发布时被删除。

如果我再次设置<SkipAction></SkipAction>ErrorLog文件夹将在发布时被删除。

如果我设置<KeyAttribute>Delete</KeyAttribute> ,则ErrorLogweb.config文件正常发布。

我的理解是,为了使用自定义跳过规则,您需要从命令行调用MSBuild,而不是从VS 2012中发布。但是,我仍然想使用我保存的发布configuration文件,而且我明白现在可以VS 2012。


我的MSBuild命令行:

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy" 

My.Website.wpp.targets:

 <?xml version="1.0" encoding="utf-8" ?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest> </PropertyGroup> <Target Name="AddCustomSkipRules"> <Message Text="Adding Custom Skip Rules" /> <ItemGroup> <MsDeploySkipRules Include="SkipErrorLogFolder1"> <SkipAction></SkipAction> <KeyAttribute>Delete</KeyAttribute> <ObjectName>dirPath</ObjectName> <AbsolutePath>$(_Escaped_WPPAllFilesInSingleFolder)\\ErrorLog$</AbsolutePath> <XPath></XPath> </MsDeploySkipRules> </ItemGroup> </Target> </Project> 

我的MSBuild输出显示自定义跳过规则,但仍然删除文件:

 GenerateMsdeployManifestFiles: Generate source manifest file for Web Deploy package/publish ... AddCustomSkipRules: Adding Custom Skip Rules MSDeployPublish: Start Web Deploy Publish the Application/package to http://testserver.domain.com/MSDEPLOYAGENTSERVICE ... Starting Web deployment task from source: manifest(C:\inetpub\wwwroot\My.Website\My.Website\obj\Release\Package\My.Website.SourceManifest.xml) to Destination: auto(). Deleting filePath (MyWeb/ErrorLog\test.txt). Updating setAcl (MyWeb/). Updating setAcl (MyWeb/). Updating filePath (MyWeb/ErrorLog\Web.config). Updating filePath (MyWeb/Web.config). Updating setAcl (MyWeb/). Updating setAcl (MyWeb/). Successfully executed Web deployment task. Publish is successfully deployed. 

编辑:事实certificate你是正确的:从Visual Studio中执行时忽略skip指令。

幸运的是,有一个解决方法。

你想要的是这样的:

 <!-- Skip the deletion of any file within the ErrorLog directory --> <MsDeploySkipRules Include="SkipErrorLogFolder1"> <SkipAction>Delete</SkipAction> <ObjectName>filePath</ObjectName> <AbsolutePath>ErrorLog</AbsolutePath> </MsDeploySkipRules> 

另外,你需要防止VS使用UI任务(这个任务似乎包含一个关于跳过规则的错误)。 你可以通过在你的wpp.targets或pubxml中声明以下内容来实现:

 <PropertyGroup> <UseMsDeployExe>true</UseMsDeployExe> </PropertyGroup> 

我已经在本地testing了这一点,我可以确认它的工作方式是:更新附加文件,但目录中没有文件被删除。

作为参考,这里是我的完整.wpp.targets文件与工作跳过规则跳过删除ErrorLog文件夹和自定义的ACL,使ErrorLog文件夹在服务器上可写。

从VS 2012 Update 3开始,只有在命令行中使用MSBuild进行发布时才能正常工作,而传递给MSBuild的DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"选项。 从VS中发布时,这不起作用。

 <?xml version="1.0" encoding="utf-8" ?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <UseMsdeployExe>true</UseMsdeployExe> <!-- Required for the MSDeploySkipRules to work --> <DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode> </PropertyGroup> <PropertyGroup> <AfterAddIisSettingAndFileContentsToSourceManifest> $(AfterAddIisSettingAndFileContentsToSourceManifest); AddCustomSkipRules; </AfterAddIisSettingAndFileContentsToSourceManifest> </PropertyGroup> <Target Name="AddCustomSkipRules"> <Message Text="Adding Custom Skip Rules" /> <ItemGroup> <MsDeploySkipRules Include="SkipErrorLogFolder"> <SkipAction>Delete</SkipAction> <ObjectName>filePath</ObjectName> <AbsolutePath>ErrorLog</AbsolutePath> <XPath></XPath> </MsDeploySkipRules> </ItemGroup> </Target> <PropertyGroup> <AfterAddIisSettingAndFileContentsToSourceManifest> $(AfterAddIisSettingAndFileContentsToSourceManifest); SetCustomACLs; </AfterAddIisSettingAndFileContentsToSourceManifest> <AfterAddDeclareParametersItemsForContentPath> $(AfterAddDeclareParametersItemsForContentPath); SetCustomAclParameters; </AfterAddDeclareParametersItemsForContentPath> </PropertyGroup> <Target Name="SetCustomACLs"> <Message Text="Setting Custom ACLs" /> <ItemGroup> <!--Make sure the application pool identity has write permission to the download folder--> <MsDeploySourceManifest Include="setAcl" Condition="$(IncludeSetAclProviderOnDestination) And Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')"> <Path>$(_MSDeployDirPath_FullPath)\ErrorLog</Path> <setAclAccess>Write</setAclAccess> <setAclResourceType>Directory</setAclResourceType> <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings> </MsDeploySourceManifest> </ItemGroup> </Target> <Target Name="SetCustomAclParameters"> <Message Text="Setting Custom ACL Parameters" /> <EscapeTextForRegularExpressions Text="$(_MSDeployDirPath_FullPath)"> <Output TaskParameter="Result" PropertyName="_EscapeRegEx_MSDeployDirPath" /> </EscapeTextForRegularExpressions> <ItemGroup> <MsDeployDeclareParameters Include="Add write permission to ErrorLog folder" Condition="$(IncludeSetAclProviderOnDestination) and Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')"> <Kind>ProviderPath</Kind> <Scope>setAcl</Scope> <Match>^$(_EscapeRegEx_MSDeployDirPath)\\ErrorLog$</Match> <Description>Add write permission to ErrorLog folder</Description> <DefaultValue>Default Web Site/ErrorLog</DefaultValue> <Value>$(DeployIisAppPath)/ErrorLog</Value> <Tags>Hidden</Tags> <Priority>$(VsSetAclPriority)</Priority> <ExcludeFromSetParameter>True</ExcludeFromSetParameter> </MsDeployDeclareParameters> </ItemGroup> </Target> </Project> 

另一种方法是避免SkipAction标记,我已经成功地使用这个设置直接从VS 2013:

 <Target Name="AddCustomSkipRules" AfterTargets="AddIisSettingAndFileContentsToSourceManifest"> <Message Text="Adding Custom Skip Rules" /> <ItemGroup> <MsDeploySkipRules Include="SkipMedia"> <objectName>dirPath</objectName> <absolutePath>media</absolutePath> </MsDeploySkipRules> <MsDeploySkipRules Include="SkipUpload"> <objectName>dirPath</objectName> <absolutePath>upload</absolutePath> </MsDeploySkipRules> </ItemGroup> </Target> 

我只能告诫说,它会忽略更新,删除和添加操作。

经过许多小时看网。 我创build这个文件为{myprojectname} .wpp.targets在站点根文件夹下。 它使用Visual Studio发布时可以工作。 媒体文件夹被忽略。 我正在使用VS 2010。

 <?xml version="1.0" encoding="utf-8" ?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <UseMsdeployExe>true</UseMsdeployExe> <!-- Required for the MSDeploySkipRules to work --> <DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode> </PropertyGroup> <PropertyGroup> <AfterAddIisSettingAndFileContentsToSourceManifest> $(AfterAddIisSettingAndFileContentsToSourceManifest); AddCustomSkipRules; </AfterAddIisSettingAndFileContentsToSourceManifest> </PropertyGroup> <Target Name="AddCustomSkipRules"> <Message Text="Adding Custom Skip Rules - WPP Targets 2" /> <ItemGroup> <MsDeploySkipRules Include="SkipErrorLogFolder"> <SkipAction>Delete</SkipAction> <ObjectName>dirPath</ObjectName> <AbsolutePath>media</AbsolutePath> <XPath></XPath> <Apply>Destination</Apply> </MsDeploySkipRules> </ItemGroup> </Target> </Project> 

我认为问题是在不正确的AbsolutePath。 它应该是一个正则expression式来匹配文件或文件夹。 所以应该妥善逃脱。 以下是为我工作的示例(我想跳过app_offline.htm以使交付部分更大的部署)

 <PropertyGroup> <PackageUsingManifestDependsOn>$(PackageUsingManifestDependsOn);AddCustomSkipRules</PackageUsingManifestDependsOn> </PropertyGroup> <Target Name="AddCustomSkipRules"> <ItemGroup> <MsDeploySkipRules Include="SkipAppOfflineOnDeploy"> <SkipAction></SkipAction> <ObjectName>filePath</ObjectName> <AbsolutePath>app_offline\.htm</AbsolutePath> <Apply>Destination</Apply> <XPath></XPath> </MsDeploySkipRules> </ItemGroup> </Target> 

适用于我:我的Web解决scheme中的我的App_Data / PublishProfiles文件夹中的完整prepprod.pubxml文件。 Web Deploy不再将文件从VS 2015的webdeploy上的cachefiles文件夹中删除。第一个PropertyGroup是通过在Visual Studio中使用Web发布GUI来自动生成的。 我添加了第二个PropertyGroup和前面的评论中的目标部分。

 <?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 http://go.microsoft.com/fwlink/?LinkID=208121. --> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <WebPublishMethod>MSDeploy</WebPublishMethod> <LastUsedBuildConfiguration>Production</LastUsedBuildConfiguration> <LastUsedPlatform>Any CPU</LastUsedPlatform> <SiteUrlToLaunchAfterPublish>{masked}</SiteUrlToLaunchAfterPublish> <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> <ExcludeApp_Data>False</ExcludeApp_Data> <MSDeployServiceURL>{masked}</MSDeployServiceURL> <DeployIisAppPath>{masked}</DeployIisAppPath> <RemoteSitePhysicalPath /> <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer> <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod> <MSDeployUseChecksum>true</MSDeployUseChecksum> <EnableMSDeployBackup>True</EnableMSDeployBackup> <UserName>{masked}</UserName> <_SavePWD>True</_SavePWD> <PublishDatabaseSettings> <Objects xmlns=""> </Objects> </PublishDatabaseSettings> <ExcludeFilesFromDeployment>packages.config;*.bat;*.sln;*.suo,*.p4ignore</ExcludeFilesFromDeployment> <ExcludeFoldersFromDeployment>packages;cachefiles;.ebextensions</ExcludeFoldersFromDeployment> </PropertyGroup> <PropertyGroup> <AfterAddIisSettingAndFileContentsToSourceManifest> $(AfterAddIisSettingAndFileContentsToSourceManifest); AddCustomSkipRules; </AfterAddIisSettingAndFileContentsToSourceManifest> </PropertyGroup> <Target Name="AddCustomSkipRules"> <Message Text="Adding Custom Skip Rules" /> <ItemGroup> <MsDeploySkipRules Include="SkipcachefilesFolder"> <objectName>dirPath</objectName> <absolutePath>cachefiles</absolutePath> </MsDeploySkipRules> </ItemGroup> </Target> </Project>