gpt4 book ai didi

visual-studio-2012 - VS2012 发布到多个位置

转载 作者:行者123 更新时间:2023-12-04 19:11:47 27 4
gpt4 key购买 nike

我目前正在使用 VS2012 中的内置发布功能将 ASP.NET MVC 站点发布到 Web 服务器上的文件系统目录共享。无论如何,当我单击“发布”按钮时,我可以将它发布到多个位置而不仅仅是一个位置吗?

我不想创建第二个配置文件并且必须两次执行相同的过程,我已经考虑通过添加附加标记来修改 pubxml 文件以查看发布例程是否将其选中。但不幸的是,它似乎只是选择了列表中的最后一个配置。

我知道理想的情况是实现 CI 解决方案,但目前我的手与发布功能有关,需要保持相对简单。

非常感谢

最佳答案

我们同样需要将我们的解决方案发布到多个文件共享位置,虽然几个月前有人问过这个问题,但我认为一个答案可以使社区受益。

由于 VS 发布配置文件是可以轻松扩展的普通 MSBuild 文件,因此这是我提供的解决方案。

请注意,我从我们的构建过程中提取了一些更复杂的代码片段,因此我不保证它无需稍作改动就可以正常工作。

在发布配置文件中,我添加了一个自定义 部署路径 项如下图所示。
请注意,您可以定义一个或多个附加位置。

<ItemGroup Label="Defines additional publish locations">
<DeploymentPaths Include="\\SERVER1\ShareFolder\ProjectA\" />
<DeploymentPaths Include="\\SERVER2\ShareFolder\ProjectA\" />
</ItemGroup>

然后我添加了一个自定义目标 自定义Web文件系统发布追赶 Web文件系统发布 .此目标调用另一个 MSBuild 文件 publish.xml,该文件执行现有文件的删除和新文件的复制。
<!-- Custom File System Publish to deploy to additional locations based on DeploymentPaths -->
<Target Name="CustomWebFileSystemPublish" AfterTargets="WebFileSystemPublish" Condition=" @(DeploymentPaths)!='' ">
<CreateItem Include="$(MSBuildProjectDirectory)\$(_PackageTempDir)">
<Output ItemName="AbsoluteSourcePathItem" TaskParameter="Include" />
</CreateItem>
<CreateProperty Value="%(AbsoluteSourcePathItem.Fullpath)">
<Output PropertyName="AbsoluteSourcePath" TaskParameter="Value" />
</CreateProperty>

<Message Text="### CustomWebFileSystemPublish" Importance="high" />
<Message Text="### DeploymentPaths: @(DeploymentPaths)" Importance="high" />

<MSBuild Projects="$(MSBuildProjectFile)" Properties="AbsoluteSourcePath=$(AbsoluteSourcePath)" Targets="DoPublish" />
</Target>

<Target Name="DoPublish">
<Message Text="### DoPublish $(AbsoluteOutputPath) | %(DeploymentPaths.Identity)" Importance="normal" />
<!-- Adjust path to the publish.xml file depending on where you put it in your solution -->
<MSBuild Projects="..\Deployment\publish.xml" Properties="OutputPath=$(AbsoluteSourcePath);DeployPath=%(DeploymentPaths.Identity)" />
</Target>

最后,这里是 publish.xml MSBuild 文件
<!-- Publish.xml -->
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Start">
<PropertyGroup>
<!-- Ensure DeployPath has the expected trailing slash -->
<DeployPath Condition=" '$(DeployPath)' != '' and !HasTrailingSlash('$(DeployPath)') ">$(DeployPath)\</DeployPath>
</PropertyGroup>
<Message Text=" # Deploying from $(OutputPath) to $(DeployPath) " Importance="normal" />
</Target>

<Target Name="CleanDeployFolder" DependsOnTargets="Start"
Condition=" $(DeployPath)!=''">
<Message Text=" # Cleaning files in $(DeployPath)" Importance="normal" />

<!-- Defines the files to clean -->
<ItemGroup>
<DeployCleanFiles Include="$(DeployPath)\**\*.*" />
</ItemGroup>

<!--Delete files in Deploy folder (folders not deleted by Delete Task)-->
<Delete Files="@(DeployCleanFiles)" />

<Message Text=" # Cleaning files in $(DeployPath) Completed" Importance="normal" />
</Target>

<Target Name="CopyToDeployFolder" DependsOnTargets="CleanDeployFolder"
Condition=" $(DeployPath)!=''">
<Message Text=" # Copying files to $(DeployPath)" Importance="normal" />

<ItemGroup>
<OutputFiles Include="$(OutputPath)\**\*.*" />
</ItemGroup>

<Copy SourceFiles="@(OutputFiles)" DestinationFolder="$(DeployPath)%(OutputFiles.RecursiveDir)" />

<Message Text=" # Copying files to $(DeployPath) Completed" Importance="normal" />
</Target>

<Target Name="Default" DependsOnTargets="CopyToDeployFolder"
Condition=" $(OutputPath)!='' And $(DeployPath)!='' ">
<Message Text=" # Deploying from $(OutputPath) to $(DeployPath) Completed" Importance="normal" />
</Target>
</Project>

关于visual-studio-2012 - VS2012 发布到多个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14277302/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com