1

csprojファイルのデバッグ構成とリリース構成の両方のプロパティ値をプログラムで変更したい。そのために4つの辞書を定義する必要がありますか?

例:DebugおよびRelease構成の "WarningLevel"プロパティ( "x86"と"AnyCPU"の値は同じままです)をWarningLevel=4に変更するとします。

var globalPropertiesReleaseX86 = new Dictionary<string, string> { { "Configuration", "Release" }, { "Platform", "x86" } };
var globalPropertiesDebugX86 = new Dictionary<string, string> { { "Configuration", "Debug" }, { "Platform", "x86" } };
var globalPropertiesReleaseAnyCPU = new Dictionary<string, string> { { "Configuration", "Debug" }, { "Platform", "x86" } };
var globalPropertiesDebugAnyCpu = new Dictionary<string, string> { { "Configuration", "Debug" }, { "Platform", "x86" } };

Project projectReleaseX86 = new ProjectCollection(globalPropertiesReleaseX86).LoadProject(filePath);
projectReleaseX86.SetProperty("WarningLevel", "4");
...and so on????

より良いアプローチがあると確信しています。任意の提案をいただければ幸いです。

前もって感謝します...

4

1 に答える 1

3

ProjectRootElementを使用できます:

var project = ProjectRootElement.Open(fileName);
project.PropertyGroups.Where(x => x.Condition.Contains("x86") || 
                                  x.Condition.Contains("AnyCPU"))
    .ToList().ForEach(x => x.AddProperty("WarningLevel", "4"));
于 2012-08-22T21:33:55.343 に答える