public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
: base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
{
string cfgname = solutionTask.Configuration;
string platform = solutionTask.Platform;
_msbuild = MSBuildEngine.CreateMSEngine(solutionTask);
_msproj = new NAnt.MSBuild.BuildEngine.Project(_msbuild);
_msproj.FullFileName = projectPath;
_msproj.LoadXml(xmlDefinition.OuterXml);
_msproj.GlobalProperties.SetProperty("Configuration", cfgname);
if (platform.Length > 0) {
_msproj.GlobalProperties.SetProperty("Platform", platform.Replace(" ", string.Empty));
}
if (outputDir != null) {
_msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName);
}
//bool targwarnings = true;
foreach (NAnt.Core.Tasks.PropertyTask property in solutionTask.CustomProperties) {
string val;
// expand properties in context of current project for non-dynamic properties
if (!property.Dynamic) {
val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.GetLocation() );
} else {
val = property.Value;
}
_msproj.GlobalProperties.SetProperty(property.PropertyName, val);
//if (property.PropertyName == "TargetWarnings") targwarnings = Boolean.Parse(val);
}
//set tools version to the msbuild version we got loaded
_msproj.ToolsVersion = SolutionTask.Project.TargetFramework.Version.ToString();
//TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly
_msproj.GlobalProperties.SetProperty("TargetFrameworkVersion", "v" + SolutionTask.Project.TargetFramework.Version.ToString());
//evaluating
_guid = _msproj.GetEvaluatedProperty("ProjectGuid");
_projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir"));
_projectPath = _msproj.GetEvaluatedProperty("ProjectPath");
//TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly
////check if we targeting something else and throw a warning
//if (targwarnings)
//{
// string verString = _msproj.GetEvaluatedProperty("TargetFrameworkVersion");
// if (verString != null)
// {
// if (verString.StartsWith("v")) verString = verString.Substring(1);
// Version ver = new Version(verString);
// if (!ver.Equals(SolutionTask.Project.TargetFramework.Version))
// {
// Log(Level.Warning, "Project '{1}' targets framework {0}.", verString, Name);
// }
// }
//}
//project configuration
ProjectEntry projectEntry = solution.ProjectEntries [_guid];
if (projectEntry != null && projectEntry.BuildConfigurations != null) {
foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) {
Configuration projectConfig = ce.Value;
ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
}
} else {
Configuration projectConfig = new Configuration (cfgname, platform);
ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
}
//references
_references = new ArrayList();
NAnt.MSBuild.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference");
foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) {
string rpath = r.FinalItemSpec;
string priv = r.GetMetadata("Private");
string hintpath = r.GetMetadata("HintPath");
string ext = r.GetMetadata("ExecutableExtension");
ReferenceBase reference = new MSBuildAssemblyReference(
xmlDefinition, ReferencesResolver, this, gacCache,
rpath, priv, hintpath, ext);
_references.Add(reference);
}
refs = _msproj.GetEvaluatedItemsByName("ProjectReference");
foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) {
string pguid = r.GetMetadata("Project");
string pname = r.GetMetadata("Name");
string rpath = r.FinalItemSpec;
string priv = r.GetMetadata("Private");
ReferenceBase reference = new MSBuildProjectReference(
ReferencesResolver, this, solution, tfc, gacCache, outputDir,
pguid, pname, rpath, priv);
_references.Add(reference);
}
}