protected override BuildResult Build(Configuration solutionConfiguration)
{
// explicitly set the Configuration and Platform
MSBuildConfiguration projectConfig = (MSBuildConfiguration) BuildConfigurations[solutionConfiguration];
_msproj.GlobalProperties.SetProperty("Configuration", projectConfig.Name);
if (!StringUtils.IsNullOrEmpty(projectConfig.PlatformName)) {
_msproj.GlobalProperties.SetProperty("PlatformTarget", projectConfig.PlatformName.Replace(" ", string.Empty));
}
//modify original references to contain full path to whatever we resolved
_msproj.RemoveItemsByName("Reference");
_msproj.RemoveItemsByName("ProjectReference");
NAnt.MSBuild.BuildEngine.BuildItemGroup refs = _msproj.AddNewItemGroup();
foreach (ReferenceBase r in _references) {
string path = r.GetPrimaryOutputFile(solutionConfiguration);
if (path == null || !File.Exists(path)) {
if (path == null) {
Log(Level.Warning, "Reference \"{0}\" of project {1} failed to be found.", r.Name, this.Name);
} else {
Log(Level.Warning, "Reference \"{0}\" of project {1} failed to be found (resolved to {2})", r.Name, this.Name, path);
}
continue;
}
NAnt.MSBuild.BuildEngine.BuildItem i = refs.AddNewItem("Reference", r.Name);
i.SetMetadata("HintPath", path);
i.SetMetadata("CopyLocal", r.CopyLocal ? "True" : "False");
}
//this should disable assembly resolution and always use hintpath (which we supply)
if(_msbuild.Assembly.GetName().Version.Major >= 4) {
//MSBuild 4 adds some system references automatically, so adding TargetFrameworkDirectory for those
_msproj.GlobalProperties.SetProperty("AssemblySearchPaths", "{HintPathFromItem};{TargetFrameworkDirectory}");
} else {
_msproj.GlobalProperties.SetProperty("AssemblySearchPaths", "{HintPathFromItem}");
}
if(_msproj.Build()) {
return BuildResult.Success;
}
return BuildResult.Failed;
}