dependencies - msbuild reference resolution -
i've been doing work analyzes relationships between various projects in source control. far i've been using powershell , xpath through select-xml cmdlet process our csproj files, relies on tenuous knowledge of how msbuild uses projectreference , reference elements in project files. dawned on me better if use msbuild resolve references , somehow inspect results of reference resolution process.
msbuild experts: seem possible? entail writing custom targets file or something? forced building projects since csproj files import microsoft.csharp.targets?
any insight nice. thanks!
it quite easy. first reference these assemblies:
microsoft.build microsoft.build.engine microsoft.build.framework microsoft.build.utilities.v4.0 ...and can create tooling around msbuild object model. i've got custom msbuild task analysis right in build, snippet below:
private bool checkreferences(string projectfullpath) { var project = new project(projectfullpath); var items = project.getitems("reference"); if (items == null) return true; foreach (var item in items) { if (item == null) continue; if (string.isnullorwhitespace(item.unevaluatedinclude)) continue; if (!item.hasmetadata("hintpath")) continue; string include = item.unevaluatedinclude; string hintpath = item.getmetadata("hintpath").unevaluatedvalue; if (!string.isnullorwhitespace(hintpath)) if (hintpath.contains(@"c:\") || hintpath.contains("c:/")) logwarning("absolute path reference in project {0}", projectfullpath); } return true; }
Comments
Post a Comment