【问题标题】:How do I mimic the Publish button in Visual Studio from within the .csproj file?如何从 .csproj 文件中模仿 Visual Studio 中的“发布”按钮?
【发布时间】:2015-06-09 02:29:15
【问题描述】:
我有一个 Visual Studio 2013 Web 应用程序项目,并且我有一个本地文件系统发布配置文件设置。当我在 Visual Studio 中右键单击项目并选择“发布”时,我可以正常发布并且一切都按预期运行。但是,我需要在构建时自动进行此发布,因为解决方案中的其他项目依赖于在本地部署的该项目。在我的例子中,部署进入 $(ProjectDir)/Deploy 文件夹。
当我使用msbuild myproject.csproj 构建此项目或右键单击构建时,我该如何做到这一点,该项目将根据 .pubxml 文件进行部署?
【问题讨论】:
标签:
asp.net
visual-studio
msbuild
【解决方案1】:
最终的解决方案是将其添加到我的 .csproj 文件的末尾。
<Target Name="Deploy" AfterTargets="Build">
<MSBuild
Projects="$(ProjectPath)"
Targets="WebPublish"
Properties="PublishProfile=LocalDeploy"
/>
</Target>
LocalDeploy 是我在$(ProjectDir)Properties/PublishProfiles 中找到的.pubxml 文件的名称。
作为参考,这里是使用的发布配置文件:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>False</EnableUpdateable>
<DebugSymbols>True</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>$(MSBuildThisFileDirectory)\..\..\Deploy</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
</Project>