Visual studio 在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则
我正在尝试使用WebDeploy发布一个网站,该网站使用自定义MSDeploy跳过规则和保存在Visual Studio 2012中的发布配置文件 我可以从命令行使用发布配置文件,但是跳过删除文件夹的跳过规则不起作用 我的web应用程序中有一个Visual studio 在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则,visual-studio,msbuild,visual-studio-2012,msdeploy,webdeploy,Visual Studio,Msbuild,Visual Studio 2012,Msdeploy,Webdeploy,我正在尝试使用WebDeploy发布一个网站,该网站使用自定义MSDeploy跳过规则和保存在Visual Studio 2012中的发布配置文件 我可以从命令行使用发布配置文件,但是跳过删除文件夹的跳过规则不起作用 我的web应用程序中有一个ErrorLog子文件夹,其中包含一个web.config文件,用于设置正确的文件夹权限。在没有任何跳过规则的情况下,ErrorLog文件夹和web.config文件将正常发布,但服务器上文件夹中的所有现有错误日志文件将在发布时删除 删除时出错 当我将自
ErrorLog
子文件夹,其中包含一个web.config
文件,用于设置正确的文件夹权限。在没有任何跳过规则的情况下,ErrorLog
文件夹和web.config
文件将正常发布,但服务器上文件夹中的所有现有错误日志文件将在发布时删除
删除
时出错
当我将自定义跳过规则添加到wpp.targets
文件时,跳过规则不再接受
元素的值。如果我设置删除
,我会得到以下错误:
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]
My.Website.wpp.targets:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"
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.
阿达斯基普鲁士酒店
删除
肮脏的
$(\u转义\u wppallfilesinglefolder)\\ErrorLog$
My MSBuild输出显示自定义跳过规则,但仍在删除文件:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"
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.
编辑:事实证明您是对的:从VisualStudio执行时忽略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>
真的
我已经在本地对此进行了测试,我可以确认它是否按预期工作:已更新附加文件,但未删除目录中的任何文件。供参考,这是我完整的
.wpp.targets
文件,使用工作跳过规则跳过删除ErrorLog
文件夹和自定义ACL,使ErrorLog
文件夹在服务器上可写
从VS 2012 Update 3开始,这仅在从命令行使用MSBuild发布时有效,且DeployOnBuild=true;PublishProfile=“测试服务器-Web部署”
传递给MSBuild的选项。从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>
真的
集成的
$(在将设置和文件内容添加到源清单之后);
阿达斯基普鲁士;
删除
文件路径
错误日志
$(在将设置和文件内容添加到源清单之后);
SetCustomACLs;
$(AfterAddDeclareParametersItemsForContentPath);
设置自定义参数;
$(\u MSDeployDirPath\u FullPath)\ErrorLog
写
目录
setAclResourceType;setAclAccess
提供者路径
setAcl
^$(\u EscapeRegEx\u MSDeployDirPath)\\ErrorLog$
向ErrorLog文件夹添加写入权限
默认网站/错误日志
$(DeployIisAppPath)/ErrorLog
隐藏的
$(VsSetAclPriority)
真的
我认为问题出在不正确的绝对路径上。它应该是与文件或文件夹匹配的正则表达式。所以它应该被正确地逃脱。下面是对我有用的示例(我想跳过app_offline.htm的删除,以使交付成为更大部署的一部分)
$(打包使用ManifestDependson);阿达斯基普鲁士酒店
文件路径
app_offline\.htm
目的地
在网上浏览了好几个小时后。我在站点根文件夹下创建了这个文件{myprojectname}.wpp.targets。它在使用visual studio发布时起作用。将忽略媒体文件夹。我正在使用VS2010
<?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>
真的
集成的
$(在将设置和文件内容添加到源清单之后);
阿达斯基普鲁士;
删除
肮脏的
媒体
目的地
另一种方法是避免使用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>
肮脏的
媒体
肮脏的
上传
据我所知,唯一需要注意的是,它将忽略更新、删除和添加操作。对我有效:我的web解决方案中我的App_Data/PublishProfiles文件夹中的完整prepprod.pubxml文件。Web部署不再从VS 2015中删除webdeploy上cachefiles文件夹中的文件。第一个PropertyGroup是在VisualStudio中使用web发布gui自动生成的。我添加了第二个PropertyGroup和前面评论中的Target部分
<?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>
MSDeploy
生产
任何CPU
{蒙面的}
真的
假的
{蒙面的}
{蒙面的}
假的
WMSVC
真的
真的
{蒙面的}
真的
packages.config;*。蝙蝠;*。sln;*。锁,*.p4忽略
包装;缓存文件;。电子扩展
$(在将设置和文件内容添加到源清单之后);
阿达斯基普鲁士;
肮脏的
缓存文件
这在vs 2015中对我有效,网站项目类型:
<!--Added inside existing <ProjectGroup> tag-->
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
<!--Added new ProjectGroup tag inside <Project></Project>-->
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
</PropertyGroup>
<!--Added inside existing <Project> tag at the bottom-->
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipConfigFolder">
<SkipAction></SkipAction>
<!--<KeyAttribute>Delete</KeyAttribute>-->
<ObjectName>dirPath</ObjectName>
<AbsolutePath>App_Data\\Composite\\Logfiles</AbsolutePath>
<XPath>
</XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
阿达斯基普鲁士酒店
MSDeploy
肮脏的
应用程序\数据\\复合\\日志文件
如果我使用如您所示的跳过规则,使用noSkipAction
值和noKeyAttribute
元素,它确实会跳过删除ErrorLog
文件夹中的文件——这很好——但它也会跳过发布