Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Last active December 11, 2015 13:04
Show Gist options
  • Save masaru-b-cl/1e6e849ffe8cf0d9a9fb to your computer and use it in GitHub Desktop.
Save masaru-b-cl/1e6e849ffe8cf0d9a9fb to your computer and use it in GitHub Desktop.
プロジェクトファイルを舐めて書き換えるLinqPadスクリプト
XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
var filenames = Directory.EnumerateFiles(
@"C:\Users\takano-s\src",
"*.vbproj",
SearchOption.AllDirectories);
foreach(var filename in filenames)
{
var doc = XDocument.Load(filename);
// OutputPathプロパティの書き換え
new List<String>(new[]{"Debug", "Release"}).ForEach(condition =>
{
var outputPath = doc.Descendants(ns + "OutputPath")
.Where(e => e.Ancestors(ns + "PropertyGroup")
.First()
.Attribute("Condition").Value
.Contains(condition))
.First();
outputPath.Value = String.Format(@".\bin\{0}\", condition);
});
// propsファイルのインポート
doc.Root.Add(
new XElement(ns + "Import",
new XAttribute("Project", @"$(ProjectDir)..\path\to\Proj.Common.props")
)
);
doc.Save(filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment