Visual Studio 2013 Build and Publish

后端 未结 2 1249
悲&欢浪女
悲&欢浪女 2020-12-19 18:40

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 proj

相关标签:
2条回答
  • 2020-12-19 19:16

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

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

    UPDATED: 2017-02-13

    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
    

    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.

    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>
    

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

    0 讨论(0)
  • 2020-12-19 19:27

    Building on @chief7's answer, I was able to get this working in an MVC project in Visual Studio 2015 like so:

    <Target Name="Deploy" AfterTargets="Build">
        <MSBuild
            Condition="'$(DeployOnBuild)'!='true'"
            Projects="$(ProjectPath)"
            Targets="WebPublish"
            Properties="PublishProfile=$(AutoDeployPublishProfileName)"/>
    </Target>
    

    The original answer was throwing MSB4006 for me:

    There is a circular dependency in the target dependency graph involving target "AfterBuild"

    This answer suggested changing the target name and adding the AfterTargets property as shown above, which worked.

    As an aside for those who need to make deployment contingent on configuration (Debug, Release, etc.)—@chief7 has a great write-up on their website.

    0 讨论(0)
提交回复
热议问题