MsBuild and MsDeploy with multiple environments

前端 未结 2 1118
生来不讨喜
生来不讨喜 2021-01-30 04:36

Are there good patterns for mapping solution configurations to environments and using MsDeploy for packaging per environment?

Shortest version: Grab this file, and try t

相关标签:
2条回答
  • 2021-01-30 04:46

    The first attempt failed because Package target doesn't exist in the solution file. When using MSBuild on a solution file, a temporary MSBuild project is created (SamplePackage.sln.metaproj); this project file contains only some targets (Build, Clean, Rebuild, Publish, ...)

    Solution : DeployOnBuild & DeployTarget properties

    One way to do what you want is to use DeployOnBuild property like this :

    <PropertyGroup Condition="'$(Configuration)' == ''">
      <Platform>Any Cpu</Platform>
      <Configuration>Dev</Configuration>
      <PackageLocation>$(MSBuildProjectDirectory)\package.zip</PackageLocation>
    </PropertyGroup>
    
    <Target Name="Build">
      <MSBuild Projects="SamplePackage.sln"
               Targets="Build"/>
    </Target>
    
    <Target Name="BuildWebPackage">
      <MSBuild Projects="SamplePackage.sln"
               Properties="Platform=$(Platform);
                           Configuration=$(Configuration);
                           DeployOnBuild=true;
                           DeployTarget=Package;
                           PackageLocation=$(PackageLocation);"/>
    </Target>
    
    • DeployOnBuild=true : deployment must be made when Build is called
    • DeployTarget=Package : for deployment creates a package
    • PackageLocation : indicates the filepath of the package file

    Additional links :

    • Creating web packages using MSBuild
    • How can I get TFS2010 to run MSDEPLOY for me through MSBUILD?
    • How to "Package/Publish" Web Site project using VS2010 and MsBuild
    • Automated Deployment in ASP.NET 4 - Frequently Asked Questions
    0 讨论(0)
  • 2021-01-30 05:05

    I've done something similar that may be useful. In a recent project, we had 'Dev', 'Test' and 'Prod' environments.

    I added solution configurations for each of these.. eg.

    • Release-Dev
    • Release-Test
    • Release-Prod

    For most projects in the solution, these configurations were just linked to the regular 'Release' build, but where appropriate, some projects did have distinct 'Release-Test' build configurations where there might be #if/#endif stuff in the code.

    This would also make sense to allow customisation for your msdeploy config per configuration too.

    Regarding the msbuild target. The target referrs to the name of a element. eg you could call msbuild with /t:BuildWebPackage for your example above.

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