0
私は、私がMSBuildで.csprojのChooseElementを作成する方法を教えてください。 Microsoft.Build.Construction</li> <li>アセンブリ::
- 名前空間を使用プログラムで.csprojファイルを作成するために、以下のようなものを作成したい(Microsoft.Build.dllで)Microsoft.Buildを
:どんなとき条件でXMLブロックの上に作成
<Choose>
<When Condition=" '$(Configuration)'=='debug' ">
<PropertyGroup>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>.\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="UnitTesting\*.cs" />
<Reference Include="NUnit.dll" />
</ItemGroup>
</When>
<When Condition=" '$(Configuration)'=='retail' ">
<PropertyGroup>
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
<OutputPath>.\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<OutputPath>.\bin\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
</Otherwise>
</Choose>
どのように私は、MSBuildのでChooseElementを作成することができますし、そうでなければブロックする。
私はこのようなコードを書きましたが、動作しません:
var root = ProjectRootElement.Create();
var choose = root.CreateChooseElement();
var when1 = root.CreateWhenElement("Condition1"); // How add tag for this one ?
var when2 = root.CreateWhenElement("Condition2");
var when3 = root.CreateWhenElement("Condition3");
var when4 = root.CreateWhenElement("Condition4");
var ow = root.CreateOtherwiseElement(); // How add tag for this one ?
choose.AppendChild(when1); // Exception Here !
choose.AppendChild(when2);
choose.AppendChild(when3);
choose.AppendChild(when4);
choose.AppendChild(ow);
root.Save("test.csproj");
例外:
An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.Build.dll
Additional information: The parent node is not itself parented.
私はこのXMLブロックが非常に複雑だと思います!
私を案内してください。