7

VS2012 .NET 4 製品には 2 つの異なる SKU の A と B があり、現在 x86 専用にビルドしています。通常の構成もあり、現在 4 つの構成があることDebugRelease意味します。

  • デバッグA
  • デバッグB
  • リリースA
  • リリースB

.csproj ファイルの 1 つを見ると、次のようになります。

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugA|x86' ">
    <OutputPath>..\bin\DebugA\</OutputPath>
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseA|x86' ">
    <OutputPath>..\bin\ReleaseA\</OutputPath>
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugB|x86' ">
    <OutputPath>..\bin\DebugB\</OutputPath>
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseB|x86' ">
    <OutputPath>..\bin\ReleaseB\</OutputPath>
</PropertyGroup>

明らかに、x64 を追加すると、これが 4 から 8 の異なる組み合わせから 2 倍になり、VS は、必要に応じて AnyCPU プラットフォーム構成も追加するようです。30 以上のプロジェクトで 8 つすべてが正しく構成されていることを確認するには、VS で何度もクリックする必要があり、間違いを犯しやすいです。

マルチターゲティングの問題が解決された他のいくつかの SO の質問と、参照パスで ${Platform} を使用することを含む、さまざまなプラットフォームのさまざまな参照を含めるための提案の 1 つを読みました。プロジェクトの設定で同様のことができると考えたので、マルチプラットフォームを実行しようとしたときにこれを試しました:

<PropertyGroup Condition=" '$(Configuration)' == 'DebugA' Or '$(Configuration)' == 'DebugB' ">
     <OutputPath>..\bin\${Platform}\${Configuration}\</OutputPath>
</PropertyGroup> 
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseA' Or '$(Configuration)' == 'ReleaseB' ">
     <OutputPath>..\bin\${Platform}\${Configuration}\</OutputPath>
</PropertyGroup> 

理論的には、たった 2 つのブロックで 8 つの異なる組み合わせすべてに必要なものが得られるはずです。しかし、VS を見ると、プロジェクトで利用可能なビルド プラットフォームとして x86 も x64 も表示されません。VS が実際にビルド プラットフォームを保存する唯一の方法は、それらをプロパティ グループの奇妙な条件としてエンコードすることであるかのように見えますか? そうじゃないって言って...

VS でうまく動作する「見栄えの良い」マルチプラットフォーム .csproj を作成する方法はありませんか?

VS が個々のプロジェクトのプロパティ ウィンドウにプラットフォームを表示できない場合でも、msbuild が正しいプラットフォームを使用することを信頼して、.csprojs を作成し、VS でそれらを編集しないことを決定できますか?

編集:

質問が少しわかりにくかったようです: 明確にするために、多くのプロジェクトと config|platform の 8 つの組み合わせがある場合に、プロジェクトの構成とソリューションのビルド構成をセットアップ、維持、および概要する方法を知りたいです。 . これを手動で行う方法は知っていますが、200 以上のプロパティ ページのいずれかで頭がおかしくなったり、間違いを犯したりすることは避けられません。

4

3 に答える 3

2

プロジェクト ファイルを一度手動で変更する必要がない場合は、すべての共有構成を構成ファイルに入れて、各プロジェクトから参照することができます。そのためには、最初に構成ファイルを作成する必要があります。このファイルは、すべてのプロジェクト間で共有するすべての情報 (ビルド構成など) を含む通常の MsBuild ファイルです。ファイルは大まかに次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5"
         DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <!-- VS information -->
        <ProductVersion>9.0.30729</ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>

        <!-- Default configuration -->
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>

        <!-- Project directories -->
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <OutputPath>$(SolutionDir)\..\build\bin\$(Platform)\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>$(SolutionDir)\..\build\temp\bin\obj\$(AssemblyName)\$(Platform)\$(Configuration)\</IntermediateOutputPath>

        <!-- Build configuration -->
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <DefineConstants>TRACE;CODE_ANALYSIS</DefineConstants>
    </PropertyGroup>
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
  • 1 つ目PropertyGroupは、全体的な定数、つまり、すべてのビルド構成のすべてのプロジェクトで使用される定数を定義します。ご覧のとおり、や などのOutputPathビルド変数を使用して、バイナリなどの場所を特定できます。$(Platform)$(Configuration)
  • 最初のものPropertyGroupには、ビジュアルスタジオによって通常定義される一連の設定もありますProductVersion。技術的には、それらを移動する必要はありませんが、それらを移動すると、プロジェクト ファイル内の混乱が軽減されます。
  • 次のセクションでは、さまざまなビルド構成のさまざまな設定を定義します。

構成ファイルを定義したら、たとえば という名前を付けBaseConfigurations.targetsてから、プロジェクト ファイルを編集する必要があります。残念ながら、すべてのプロジェクト ファイルを確認する必要がありますが、これを行う必要があるのは 1 回だけです。構成ファイルをリンクした後は、構成ファイルを変更することで、すべての共有構成を変更できます。

通常のプロジェクト ファイルは、おおよそ次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{33017F71-5A1C-4113-9041-4DD3F58921D0}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyProject</RootNamespace>
    <AssemblyName>MyProject</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

構成ファイルをリンクするには、次のことを行う必要があります。

  • PropertyGroup構成ファイルで既に定義されている最初のものから削除します
  • 行を追加します<SolutionDir Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">$(MSBuildProjectDirectory)\..</SolutionDir>。これは、Visual Studio からのみビルドする場合は必要ありませんが (Visual Studio がSolutionDir変数を自動的に定義するため)、MsBuild を介してプロジェクトをビルドする場合にも必要です。この行は、各プロジェクトが独自のサブディレクトリにあり、ソリューション ファイルが各プロジェクト ファイルの 1 つ上のディレクトリにあることも想定しています。つまり、構造は次のようになります。

    source
        MyProject
            MyProject.csproj
        MySolution.sln 
    
  • 最初の行のすぐ下にPropertyGroup、次の行を追加します<Import Project="$(SolutionDir)\BaseConfiguration.targets" />。これは、構成ファイルをインポートする必要があることを MsBuild (および Visual Studio) に示します。

  • ビルド構成を削除する
  • ファイルの最後にある行を削除します<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />。これは構成ファイルで定義されているため、不要になりました。

このすべての後、プロジェクト ファイルは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <SolutionDir Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">$(MSBuildProjectDirectory)\..</SolutionDir>
    <ProjectGuid>{33017F71-5A1C-4113-9041-4DD3F58921D0}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>MyProject</RootNamespace>
    <AssemblyName>MyProject</AssemblyName>
  </PropertyGroup>
  <Import Project="$(SolutionDir)\BaseConfiguration.targets" />
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

ノート:

  • このアプローチに従うと、Visual Studio はさまざまなビルド構成をすべて認識し、適切なものを選択できるようになります。特定のソリューション構成にプロジェクトを含めたり除外したりするには、ソリューションの「構成マネージャー」に移動する必要がある場合があることに注意してください。
  • このアプローチに従うと、プロジェクトのプロパティ ページからグローバルに定義されたプロパティを変更できなくなります。構成ファイルに変更を加える必要があります。変更は、すべてのプロジェクトのプロパティに反映されます。
  • Visual Studio 2010 以前を使用している場合、構成ファイルに変更を加えた場合、Visual Studio 2010 はインクルード ファイルへの変更を検出しないため、ソリューションを再読み込みする必要があります (開いている場合)。Visual Studio 2012 は、インクルード ファイルへの変更を検出できるはずです。
于 2013-08-12T20:55:57.410 に答える
0

実行したいさまざまなビルドを選択できるバッチビルドが必要です。

ここに画像の説明を入力

これを Tools -> Options -> Keyboard でキーボード ショートカットにマップし、Build.BatchBuild を検索できます。

于 2013-04-14T04:07:27.183 に答える