gpt4 book ai didi

msbuild - 使用MSBuild生成多个配置

转载 作者:行者123 更新时间:2023-12-03 11:24:17 27 4
gpt4 key购买 nike

我正在尝试编辑我的项目文件,以使我拥有一个可以一次构建多个构建配置的项目。我使用批处理方法和MSBuild任务(参见下文)完成了此操作。

如果运行脚本,则会收到以下错误消息:

Error 103 The OutputPath property is not set for project "ThisMSBuildProjectFile.csproj". Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'.



如果我从MSBuild任务添加或省略OutputPath,则会得到此信息。如果使用VS2010调试器来逐步执行脚本并调用MSBuild任务-调试器将再次进入文件,然后进入OutputPath,那么afaik,它应该获取该值,不是吗?

任何帮助都将不胜感激-这让我发疯。谢谢,保罗。

ThisMSBuildProjectFile.csproj(多余的东西取出来):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

<!-- Only Import normal targets if not building multiple projects -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition="'$(Configuration)|$(Platform)' != 'AllBuild|AnyCPU' "/>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>C:\Folder\Etc\Output\$(Configuration)\</OutputPath>
<OutDir>C:\Folder\Etc\Output\$(Configuration)\</OutDir>
<BaseOutputPath>C:\Folder\Etc\Output\$(Configuration)\</BaseOutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<!-- Common -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Platform>AnyCPU</Platform>
<!-- Repeated properties from above here (including, of course, OutputPath) -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<!-- Repeated properties from above here (including, of course, OutputPath) -->
</PropertyGroup>

<ItemGroup>
<Projects Include="C:\Folder\Etc\ThisMSBuildProjectFile.csproj" />
</ItemGroup>

<!-- Call this project file again, but with a different configuration - if this was working, this would call multiple build configs -->
<Target Name="Build" Condition="'$(Configuration)|$(Platform)' == 'AllBuild|AnyCPU' ">
<Message Text="hm!"/>
<!-- Tried thiswith and without the OutputPath property - makes no difference. -->
<MSBuild Projects="@(Projects)" Properties="Configuration=Debug;OutputPath=C:\Folder\Etc\Output\" ToolsVersion="4.0" Condition="'$(Configuration)|$(Platform)' == 'AllBuild|AnyCPU' "/>
</Target>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AllBuild|AnyCPU' ">
<!-- Repeated properties from above here (including, of course, OutputPath) -->
</PropertyGroup>

<!-- Project files -->
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Blah\Blah.cs" />
</ItemGroup>

最佳答案

重要的是要意识到,当您使用“MSBuild”任务时,将启动一个新的子MSBuild进程。这意味着您在父MSBuild进程中定义的所有项和属性都将而不是自动传递给子MSBuild进程 /从其可见。 。

为了回答您的问题,我编写了以下独立的示例,该示例针对所有指定的配置运行子MSBuild项目:

  • 首先,为您的MSBuild实验创建一个目录(例如,我使用Properties)
  • 在此目录中,创建第一个文件MSBuild:
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
    <ItemGroup>
    <ConfigList Condition=" '@(ConfigList)' == '' and $(Config) != '' " Include="$(Config.Split('+'))" /><!-- parse all requested configurations into a list -->
    <ConfigList Condition=" '@(ConfigList)' == '' " Include="Debug" /><!-- if no configurations were specified, default to Debug -->
    </ItemGroup>
    <!--

    Build the child project for each requested configuration. -->
    <Target Name="Build">
    <MSBuild Projects="$(MSBuildProjectDirectory)\child.proj" Properties="Configuration=%(ConfigList.Identity);OutputPath=$(MSBuildProjectDirectory)\bin\%(ConfigList.Identity)" Targets="Build" />
    </Target>
    </Project>
  • 在同一目录中,创建第二个文件<MSbuild Properties="..." />(在您的情况下,这将是您要构建的实际C#项目,但是由于我试图说明我的观点,因此我使用了一个简单的子项目,而不是运行C#编译器只是打印属性值:-))
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
    <Target Name="Build">
    <Message Text="Building configuration $(Configuration) with output path $(OutputPath)" Importance="High" />
    </Target>
    </Project>
  • 现在您可以运行该示例。首先是默认值,如果您未明确指定要配置的配置:
    C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild main.proj
    > (cut the noise)
    > Build:
    > Building configuration Debug with output path C:\temp_c\d\bin\Debug

    然后显式指定多个配置:
    C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild main.proj /property:Config=Debug+Release+Staging+Production
    > (cut the noise)
    > Build:
    > Building configuration Debug with output path C:\temp_c\d\bin\Debug
    > Build:
    > Building configuration Release with output path C:\temp_c\d\bin\Release
    > Build:
    > Building configuration Staging with output path C:\temp_c\d\bin\Staging
    > Build:
    > Building configuration Production with output path C:\temp_c\d\bin\Production

  • 您应该能够使这种技术适应您的情况。

    关于msbuild - 使用MSBuild生成多个配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5511274/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com