Visual Studio 2013生成和发布 [英] Visual Studio 2013 Build and Publish

查看:129
本文介绍了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...

我创建了看起来像

<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)..\..\bin\PublishFolder\</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

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

I can publish from the command line using msbuild as

msbuild C:\work\Source\AppManager\SereverManager.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年2月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)\MSBuild\14.0\Bin\MSBuild" /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天全站免登陆