Visual Studio 2013 构建和发布 [英] Visual Studio 2013 Build and Publish

查看:25
本文介绍了Visual Studio 2013 构建和发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS 2013 中混合了 web 和 windows 项目.我有一个解决方案来构建所有项目.出于测试目的,我想将一些 Web 项目自动部署到本地文件夹中.我可以手动执行此操作,右键单击菜单并选择发布...

I have mixed web and windows projects in VS 2013. I have a solution to build all the projects. For testing purposes I would like to automatically deploy some of the web projects into a local folder. I can do that manually, right click menu and select publish...

我已经创建了如下所示的发布配置文件

I have created publish profile which looks like

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>$(MSBuildThisFileDirectory)....inPublishFolder</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

我可以使用 msbuild as 从命令行发布

I can publish from the command line using msbuild as

msbuild C:workSourceAppManagerSereverManager.csproj  /p:DeployOnBuild=true /p:PublishProfile=Local 

这也给了我设计的结果.

That gives me the designed outcome as well.

我想做的是结合项目构建和发布.这意味着我希望每次构建项目时都自动部署.

What I would like to do is combine project build and publish. Which means I would like to deploy automatically every time I build the project.

我尝试设置批处理文件并从构建后事件调用 msbuild,但这会导致 VS 冻结,甚至不确定这是否是正确的方法.每次构建项目时都可以修改我的csproj文件以发布吗?

I tried setting a batch file and calling msbuild from post-build event, but that causes VS to freeze, not even sure if that is the right approach. Is it possible to modify my csproj file to publish every time I build the project?

推荐答案

是的,这绝对有可能.只需将以下 XML 添加到您的 ServerManager.csproj 文件中.

Yes, this is absolutely possible. Simply add the following XML to your ServerManager.csproj file.

  <PropertyGroup>
    <DeployOnBuild>true</DeployOnBuild>
    <PublishProfile>Local</PublishProfile>
  </PropertyGroup>

更新:2017-02-13

UPDATED: 2017-02-13

在实际测试此解决方案后,我发现 Yusuf 是正确的,并且只有当我在 MSBuild.exe 调用上显式设置 DeployOnBuildPublishProfile MSBuild 属性时,部署才有效.

After actually testing this solution I found Yusuf was correct and the deployment only worked when I explicitly set the DeployOnBuild and PublishProfile MSBuild properties on the MSBuild.exe call.

>"c:Program Files (x86)MSBuild14.0BinMSBuild" /p:DeployOnBuild=true /p:PublishProfile=Local

在 .csproj 中设置属性通常没有问题.DeployOnBuild 属性似乎很特殊.不确定这是一个错误还是故意的,但在项目文件或引用的目标文件中设置它会在构建中的某处被覆盖.只有当您通过将其设置为 MSBuild.exe 调用上的标志将其定义为全局 MSBuild 属性时,它才会受到尊重.

Setting properties in the .csproj generally works without issue. It appears the DeployOnBuild property is special. Not sure if this is a bug or intentional but setting it in the project file or a referenced targets file is overwritten somewhere in the build. Only when you define it as a global MSBuild property by setting it as a flag on the MSBuild.exe call is it respected.

一旦我发现了这一点,我就找到了一个可行的替代解决方案.将属性传递给项目中的第二个 MSBuild 调用:

Once I discovered this I found an alternate solution that works. Pass the properties to a second MSBuild call in your project:

<Target Name="AfterBuild">
  <MSBuild Condition="'$(DeployOnBuild)'!='true'" Projects="$(MSBuildProjectFullPath)" Properties="DeployOnBuild=true;PublishProfile=Local;BuildingInsideVisualStudio=False"/>
</Target>

现在无论您是在 VS 中构建还是从命令行构建,它都会自动部署.

Now it will automatically deploy whether you build in VS or from the commandline.

这篇关于Visual Studio 2013 构建和发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆