在没有MSBuild或插件的情况下在Visual Studio中顺序构建配置? [英] Sequentially build configurations in Visual Studio without MSBuild or plugins?

查看:77
本文介绍了在没有MSBuild或插件的情况下在Visual Studio中顺序构建配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN 描述了如何创建批处理版本,但没有提供自动执行不同批处理的方法(以及GUI的一键式解决方案)

MSDN describes how to create a batch build, but does not provide a way to automate different batches (and one click solution for the GUI)

此问题描述了有条件地调用第二个构建,但似乎不能满足两个以上的顺序配置

This question describes conditionally invoking a second build but doesn't appear to suffice for more than two sequential configurations

这个问题解决了相同的情况,但仅适用于两种配置

This question addresses the same situation, but again only for two configurations

在我的测试案例中,每种配置:

In my test case, each configuration:

  • 定义自己的MACROS(影响源代码)
  • 适用于多个项目(类库).这些项目是相互依赖的,并且在当前配置的上下文中需要特定的构建顺序

我希望Visual Studio使用一个构建命令按顺序构建多个配置.

I would like visual studio to build multiple configurations sequentially with a single build command.

子级配置可以嵌套在父级配置下,并在构建父级配置时由Visual Studio顺序执行吗?

Can child configurations be nested under a parent configuration, and be executed sequentially by visual studio when the parent configuration is built?

更新:尝试的解决方案1 ​​ [2016-03-11]

UPDATE : ATTEMPTED SOLUTION 1 [2016-03-11]

针对Stijn的建议答案,我尝试了以下操作:

In response to Stijn's suggested answer I've tried the following:

使用3个测试项目和6种配置来设置DotNetFramework 4.5 WinForms解决方案:

Setup DotNetFramework 4.5 WinForms solution with 3 test projects and with 6 Configurations:

  • CORE_DEBUG
  • CORE_RELEASE
  • EXTENDED_DEBUG
  • EXTENDED_RELEASE
  • 调试
  • 发布

调试配置必须:

  • 不要触发它自己的配置版本(即调试")
  • 必须按顺序触发CORE_DEBUG和EXTENDED_DEBUG配置

我已将以下修改后的目标添加到第一个项目的项目文件中:

I've added the following modified target to the first project's project file:

<Target Name="AfterBuild" Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">

现在使用调试"配置进行构建,将触发EXTENDED_RELEASE构建.查看解决方案文件后,我发现Visual Studio决定自动将调试"链接到"EXTENDED_RELEASE":

Building with the 'Debug' Configuration now, causes an EXTENDED_RELEASE build to trigger. Having a look at the solution file, I see that Visual Studio decided to automatically link 'Debug' to 'EXTENDED_RELEASE':

    {4F9706AA-26A9-483C-81C4-22E301C54C89}.Debug|Any CPU.ActiveCfg = EXTENDED_RELEASE|Any CPU
    {4F9706AA-26A9-483C-81C4-22E301C54C89}.Debug|Any CPU.Build.0 = EXTENDED_RELEASE|Any CPU

从解决方案文件中删除上述两行无济于事,因为Visual Studio只是重新生成它们.总而言之,这现在有两个不利的结果:

Removing the above two lines from the solution file doesn't help, since Visual Studio just regenerates them. In summary this now has two undesirable outcomes:

  1. Visual Studio为Project1执行调试"构建
  2. 然后,Visual Studio为Project2和Project3执行'EXTENDED_RELEASE'

结论:尽管这种方法可以工作,但它(首先)还分别执行调试和发布配置构建.视觉工作室 还会在构建菜单中列出所有6种配置(我们只需要Debug 和发布可见,并且调试必须在后台触发 CORE_DEBUG和EXTENDED_DEBUG,以及Release必须触发CORE_RELEASE 和EXTENDED_RELEASE)

Conclusion: While this approach can work, it also (first) performs debug and release configuration builds respectively. Visual Studio also lists all 6 Configurations in the build menu (we only want Debug and Release to be visible, and behind the scenes Debug must trigger CORE_DEBUG and EXTENDED_DEBUG, and Release must trigger CORE_RELEASE and EXTENDED_RELEASE)


更新:尝试的解决方案2 [2016-03-16]


UPDATE : ATTEMPTED SOLUTION 2 [2016-03-16]

继续使用makefile项目解决方案:我已经按照下面的stijn的答案指定了一个makefile项目,并且效果很好!

Moving on to a makefile project solution: I've created a makefile project as specified by stijn's answer below, and it worked perfectly!

结论:我认为这是首选的解决方案,因为它为用户提供了最大的权力和能力,可以准确地控制必须如何执行构建以及如何处理配置.

Conclusion : This is the preferred solution in my opinion because it gives the user the most power and ability to control exactly how the build(s) must be executed and how the configurations must be handled.

推荐答案

第二个

The principle of the second SO question can be adjusted to build more than one configuration/platform sequentially by just invoking MsBuild multiple times. For instance:

<Target Name="AfterBuild" Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
  <MSBuild Projects="$(MySolution)" Properties="Configuration=Release;Platform=x86"/>
  <MSBuild Projects="$(MySolution)" Properties="Configuration=Debug;Platform=x64"/>
  <MSBuild Projects="$(MySolution)" Properties="Configuration=Release;Platform=x64"/>
</Target>

这可以通过使用项目批处理,删除条件并自动确定要调用的配置,然后仅构建其他配置等来清理,但这在本文的范围之外.

This can be cleaned up by using item batching, removing the condition and instead automatically determining which config is invoked and then only building the others etc but that's a bit out of scope here.

我并不是真的相信在AfterBuild目标中执行此操作是最好的方法,因为那样的话,您就需要调整一个正常"项目来触发其他所有内容的构建.另一种方法是将 MakeFile项目添加到您的解决方案中,进行设置它是依赖关系,因此它在构建顺序中排在最后(至少在您需要的时候),并设置它的命令行以类似于上述方法调用msbuild.您甚至可以将所有逻辑保留在同一项目文件中:将构建命令行"设置为

I'm not really convinced doing this in an AfterBuild target is the best way though, because then you'd need to adjust one of your 'normal' projects to also trigger a build of everything else. An alternative is to add a MakeFile Project to your solution, set up it's dependencies so that it comes last in the build order (at least if that is what you need), and set it's command line to invoke msbuild in a way similar as described above. You can even keep all logic in the same project file: set the 'Build Command Line' to

msbuild $(MsBuildThisFile) /t:CustomBuild /p:Configuration=$(Configuration);Platform=$(Platform)

因此,构建项目将递归",并使其具有与VS所调用的相同的属性来再次调用自身,但要执行CustomBuild目标,然后您可以在其中构建其他项目/解决方案以进行品尝.

so building the project will 'recurse' and make it call itself again with the same properties as called with by VS, but executing the CustomBuild target where you can then build your other projects/solutions to taste.

编辑回复:更新 您快要准备好了,但是您必须转到Configuration Manager并确保开始时正确设置了配置.从一开始:

EDIT re: update You're almost there, but you have to go to Configuration Manager and make sure the configurations are setup properly to begin with. From the start:

  • 创建新解决方案,添加3个项目
  • 右键单击解决方案,选择 Configuration Manager
  • 活动解决方案配置组合框中,选择 new
  • 输入名称的CORE_DEBUG,在 Copy settings from 下选择DEBUG,并确保选中 Create new project configuration ,如
  • 重复其他配置
  • 例如,对于
  • EXTENDED_RELEASE,它现在应该看起来像
  • 您可能已经完成了大部分操作,但是以某种方式将Debug以某种方式分配给EXTENDED_RELEASE,因此您应该解决这一问题;您可以通过手动编辑解决方案来做到这一点,但是不必删除行,而必须编辑它们以确保正确,否则VS会再次添加它们,正如您注意到的那样
  • create new solution, add 3 projects
  • right-click solution, select Configuration Manager
  • in the Active solution configuration combobox select new
  • enter CORE_DEBUG for name, select DEBUG under Copy settings from and make sure the Create new project configurations is checked like
  • repeat for other configurations
  • for EXTENDED_RELEASE for instance, it should now look like
  • you probably did most of this already, but somehow Debug got assigned to EXTENDED_RELEASE somehow so that is one thing you should fix; you could do that by editing the solution manually but instead of removing lines you'd have to edit them to be correct else VS just adds them again, as you noticed

现在在文本编辑器中打开第一个项目,然后在已插入AfterBuild但已将其注释掉的文件的末尾附近添加

Now open first project in a text editor and near the end of the file where AfterBuild is already inserted but commented out, add

<ItemGroup>
  <Configurations Condition="'$(Configuration)'=='Debug'" Include="CORE_DEBUG;EXTENDED_DEBUG" />
  <Configurations Condition="'$(Configuration)'=='Release'" Include="CORE_RELEASE;EXTENDED_RELEASE" />
  <Projects Include="$(SolutionDir)WindowsFormsApplication1.csproj;$(SolutionDir)WindowsFormsApplication2.csproj;$(SolutionDir)WindowsFormsApplication3.csproj" />
</ItemGroup>
<Target Name="AfterBuild" Condition="'@(Configurations)' != ''">
  <Message Text="Projects=@(Projects) Configuration=%(Configurations.Identity)" />
  <MSBuild Projects="@(Projects)" Targets="Build" Properties="Configuration=%(Configurations.Identity)" />
</Target>

您可能需要调整项目的路径.这将为Debug版本构建CORE_DEBUG和EXTENDED_DEBUG,对于Release版本也将构建CORE_DEBUG和EXTENDED_DEBUG.当Configurations ItemGroup为空时,即不构建Debug或Release时,将跳过AfterBuild.

you might need to adjust the paths to the projects. This will build CORE_DEBUG and EXTENDED_DEBUG for Debug builds, and likewise for Release builds. AfterBuild is skipped when the Configurations ItemGroup is empty, i.e. when not building Debug or Release which is exactly the point.

修改为:makefile

您可以为makefile命令行指定多个命令.单击构建命令行"框旁边的箭头,然后选择''.为确保一切正确,必须将Configuration Manager设置为仅为Debug/Release构建makefile项目,例如:

You can specify multiple commands for the makefile commandline. Click the arrow next to the 'Build Command Line' box and select '' To be sure you have everything right, Configuration Manager has to be set up to only build the makefile project for Debug/Release like:

和makefile项目的命令行类似于

and the makefile project's commandline looks like

或者,我更喜欢这个,您创建了一个msbuild文件,其内容与上面相同:

Alternatively, and I'd prefer this myself, you create an msbuild file with the same content as above:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Configurations Condition="'$(Configuration)'=='Debug'" Include="CORE_DEBUG;EXTENDED_DEBUG" />
    <Configurations Condition="'$(Configuration)'=='Release'" Include="CORE_RELEASE;EXTENDED_RELEASE" />
    <Projects Include="$(SolutionDir)WindowsFormsApplication1.csproj;$(SolutionDir)WindowsFormsApplication2.csproj;$(SolutionDir)WindowsFormsApplication3.csproj" />
  </ItemGroup>
  <Target Name="Build" Condition="'@(Configurations)' != ''">
    <Message Text="Projects=@(Projects) Configuration=%(Configurations.Identity)" />
    <MSBuild Projects="@(Projects)" Targets="Build" Properties="Configuration=%(Configurations.Identity)" />
  </Target>
</Project>

然后您的makefile命令将调用该文件,如

and your makefile command then invokes that file like

msbuild /path/to/msbuildfile /t:Build /p:Configuration=Debug;SolutionDir=$(SolutionDir)

这篇关于在没有MSBuild或插件的情况下在Visual Studio中顺序构建配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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