我使用以下脚本将我的 ASP.NET MVC 应用程序部署到我们的 Web 服务器:
I use the following script to deploy my ASP.NET MVC app to our web server:
C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe MySolution.sln^
/p:Configuration=TeamCity-Test^
/p:OutputPath=bin^
/p:DeployOnBuild=True^
/p:DeployTarget=MSDeployPublish^
/p:MsDeployServiceUrl=https://mywebserver.com:8172/msdeploy.axd^
/p:username=MyDomainMyUser^
/p:password=MyPassword^
/p:AllowUntrustedCertificate=True^
/p:DeployIisAppPath=mywebsitename.com^
/p:MSDeployPublishMethod=WMSVC
现在我需要指定不同步/uploads 文件夹.我可以在这个脚本中指定吗?谢谢!
Now I need to specify to not sync the /uploads folder. Can I specify that in this script? Thanks!
说明:我的项目中有 Uploads 文件夹.我想让 Web Deploy 创建文件夹.我不希望它从我的网络服务器中删除文件夹/子文件夹/文件,因为它包含用户上传的内容.
Clarification: I have the Uploads folder in my project. I'd like for Web Deploy to create the folder. I do not want it to delete the folder/subfolders/files from my web server because it contains user-uploaded content.
说明 #2:我刚刚找到了 SkipExtraFilesOnServer=True
选项.但是,我不希望这是全球性的.我想将其设置为单个文件夹.
Clarification #2:
I just found the SkipExtraFilesOnServer=True
option. However, I don't want this to be global. I'd like to set it to a single folder.
更新:显然,您真正想要的是阻止 web 部署删除目标服务器上的现有目录,但仍然创建文件夹以防万一它不存在.您可以按以下方式完成此操作:
UPDATE: Apparently, what you really want is prevent web deploy from removing existing directory on the destination server, but still have the folder created in case it's not there. You can accomplish this as follows:
在您旁边创建 YourWebProjectName.wpp.targets 文件,项目文件包含以下内容:
create YourWebProjectName.wpp.targets file next to you the project file with the following content:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<MsDeploySkipRules Include="SkipELMAHFolderFiles">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>$(_DestinationContentPath)\NameOfYourFolder\.*</AbsolutePath>
<Apply>Destination</Apply>
<XPath></XPath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="SkipELMAHFolderChildFolders">
<SkipAction></SkipAction>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>$(_DestinationContentPath)\NameOfYourFolder\.*\*</AbsolutePath>
<Apply>Destination</Apply>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Project>
相应地更改 NameOfYourFolder
和 YourWebProjectName
.这假设您将它放在根目录中,我相信,如果不是这种情况,您可以使用相对路径.
Change NameOfYourFolder
and YourWebProjectName
accordingly. This assumes, you have it in the root, I believe, you can use relative path if it's not the case.
MsDeploySkipRules
条目告诉 webdeploy 不要删除 Name_OfYourFolder 中的任何文件.MsDeploySkipRules
告诉 webdeploy 不要删除 Name_OfYourFolder 中的任何子文件夹.MsDeploySkipRules
entry tells webdeploy not to remove any files in Name_OfYourFolder.MsDeploySkipRules
tells webdeploy not to remove any child folders in Name_OfYourFolder.此外,如果目标服务器上不存在该文件夹,则要创建该文件夹,您必须执行以下操作:
Also, to have the folder created if it's not present on the destination server, you have to do the following:
DeployemntPlaceholder.txt 需要告诉 MSBUild 将文件夹添加到包中:忽略空文件夹.
DeployemntPlaceholder.txt is required to tell MSBUild to add the folder into the package: empty folders are ignored.
我已经测试了这种方法,当您按照您展示的方式运行发布时,它可以正常工作.我已经使用 this answer 来获得正确的 msbuild 项语法.我相信,这是一种自定义标志的 MSBuild 方式,由 MSBuild 部署管道传递给 webdeploy.
I've tested this approach and it works fine when you run publish in the manner you've shown. I've used this answer to get the msbuild items syntaxt right. I believe, this is a MSBuild way to customize flags, passed to webdeploy by MSBuild Deployment Pipeline.
如果您直接运行 MSDeploy,则可以按以下方式使用跳过参数:
If you ran MSDeploy directly, you could use skip arguments in the following manner:
-skip:objectname='filePath',absolutepath='logs\.*\someNameToExclude.txt'
更新 2
考虑到原始问题指定文件夹在 Web Deploy 中不同步",最简单的方法如下:
Conserning the original question "Specifying folders not to sync in Web Deploy", the easiest way to do this is as follows:
您可以创建发布配置文件并添加以下行:
You can create a publish profile and add the following lines:
<PropertyGroup>
<ExcludeFilesFromDeployment>
File1.aspx;File2.aspx
</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>
Folder1;Folder2
</ExcludeFoldersFromDeployment>
</PropertyGroup>
我已经测试了这种方法以使用发布配置文件排除文件.一个简单的指南是这里(滚动到编辑 .pubxml 文件以排除 robots.txt 部分.
I've tested this approach for excluding files using publish profiles. An easy guide is here (scroll to Edit the .pubxml file to exclude robots.txt section).
您也可以在 .wpp.targets 文件中执行此操作或编辑您的 csproj.在 Visual Studio 和 ASP.NET 的 Web 部署常见问题解答中查看更多信息一个>
You can also do this in .wpp.targets file or edit you csproj. See more information at Web Deployment FAQ for Visual Studio and ASP.NET
这篇关于在 Web Deploy 中指定不同步的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!