public void UpdateProject (MSBuildProject msproject) { EnsureNuGetPackageBuildImportsTargetUpdater currentUpdater = Updater; if (currentUpdater != null) { currentUpdater.UpdateProject (msproject); } }
internal MSBuildPropertyEvaluated (MSBuildProject project, string name, string value, string evaluatedValue) { ParentProject = project; this.evaluatedValue = evaluatedValue; this.value = value; this.name = name; }
internal protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject project) { base.OnWriteProject (monitor, project); HashSet<string> validProjitems = new HashSet<string> (); foreach (var r in Project.References.Where (rp => rp.ReferenceType == ReferenceType.Project)) { var ip = r.GetItemsProjectPath (); if (!string.IsNullOrEmpty (ip)) { ip = MSBuildProjectService.ToMSBuildPath (Project.ItemDirectory, ip); validProjitems.Add (ip); if (!project.Imports.Any (im => im.Project == ip)) { // If there is already a Shared import, place the new import in the same location MSBuildObject before = project.Imports.FirstOrDefault (i => i.Label == "Shared" && i.Project.EndsWith (".projitems")); if (before == null) { var fsharpProject = project.ProjectTypeGuids.Contains("{F2A71F9B-5D33-465A-A702-920D77279786}"); if (fsharpProject) //For F# use the first item group as the shared project files have to be listed first before = project.ItemGroups.FirstOrDefault (i => i.Label != "Shared"); else before = project.Imports.FirstOrDefault (i => i.Label != "Shared"); } var im = project.AddNewImport (ip, beforeObject: before); im.Label = "Shared"; im.Condition = "Exists('" + ip + "')"; } } } foreach (var im in project.Imports.ToArray ()) { if (im.Label == "Shared" && im.Project.EndsWith (".projitems") && !(validProjitems.Contains (im.Project))) project.RemoveImport (im.Project); } }
public MSBuildEvaluationContext (MSBuildEvaluationContext parentContext) { this.parentContext = parentContext; this.project = parentContext.project; this.propertiesWithTransforms = parentContext.propertiesWithTransforms; this.propertiesWithTransformsSorted = parentContext.propertiesWithTransformsSorted; }
public void UpdateProject (MSBuildProject project) { if (String.IsNullOrEmpty (name)) return; project.AddImportIfMissing (name, location, condition); }
internal void InitEvaluation (MSBuildProject project) { this.project = project; // Project file properties properties.Add ("MSBuildThisFile", Path.GetFileName (project.FileName)); properties.Add ("MSBuildThisFileName", project.FileName.FileNameWithoutExtension); properties.Add ("MSBuildThisFileExtension", Path.GetExtension (project.FileName)); properties.Add ("MSBuildThisFileFullPath", MSBuildProjectService.ToMSBuildPath (null, project.FileName.FullPath)); string dir = Path.GetDirectoryName (project.FileName) + Path.DirectorySeparatorChar; properties.Add ("MSBuildThisFileDirectory", MSBuildProjectService.ToMSBuildPath (null, dir)); properties.Add ("MSBuildThisFileDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath (null, dir.Substring (Path.GetPathRoot (dir).Length))); // Properties only set for the root project, not for imported projects if (parentContext == null) { properties.Add ("VisualStudioReferenceAssemblyVersion", project.ToolsVersion + ".0.0"); properties.Add ("MSBuildProjectDefaultTargets", project.DefaultTargets); properties.Add ("MSBuildProjectExtension", Path.GetExtension (project.FileName)); properties.Add ("MSBuildProjectFile", project.FileName.FileName); properties.Add ("MSBuildProjectFullPath", MSBuildProjectService.ToMSBuildPath (null, project.FileName.FullPath.ToString())); properties.Add ("MSBuildProjectName", project.FileName.FileNameWithoutExtension); dir = project.BaseDirectory.IsNullOrEmpty ? Environment.CurrentDirectory : project.BaseDirectory.ToString(); properties.Add ("MSBuildProjectDirectory", MSBuildProjectService.ToMSBuildPath (null, dir)); properties.Add ("MSBuildProjectDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath (null, dir.Substring (Path.GetPathRoot (dir).Length))); string toolsVersion = project.ToolsVersion; if (string.IsNullOrEmpty (toolsVersion) || Version.Parse (toolsVersion) < new Version ("12.0")) toolsVersion = "12.0"; string toolsPath = ToolLocationHelper.GetPathToBuildTools ("12.0"); var frameworkToolsPath = ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.VersionLatest); properties.Add ("MSBuildBinPath", MSBuildProjectService.ToMSBuildPath (null, toolsPath)); properties.Add ("MSBuildToolsPath", MSBuildProjectService.ToMSBuildPath (null, toolsPath)); properties.Add ("MSBuildToolsRoot", MSBuildProjectService.ToMSBuildPath (null, Path.GetDirectoryName (toolsPath))); properties.Add ("MSBuildToolsVersion", toolsVersion); properties.Add ("OS", Platform.IsWindows ? "Windows_NT" : "Unix"); properties.Add ("MSBuildBinPath32", MSBuildProjectService.ToMSBuildPath (null, toolsPath)); properties.Add ("MSBuildFrameworkToolsPath", MSBuildProjectService.ToMSBuildPath (null, frameworkToolsPath)); properties.Add ("MSBuildFrameworkToolsPath32", MSBuildProjectService.ToMSBuildPath (null, frameworkToolsPath)); if (!String.IsNullOrEmpty (DefaultExtensionsPath)) { var ep = MSBuildProjectService.ToMSBuildPath (null, extensionsPath); properties.Add ("MSBuildExtensionsPath", ep); properties.Add ("MSBuildExtensionsPath32", ep); properties.Add ("MSBuildExtensionsPath64", ep); } // Environment properties.Add ("MSBuildProgramFiles32", MSBuildProjectService.ToMSBuildPath (null, Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86))); } }
static MSBuildProject LoadAndEvaluate (string dir, string testFile) { string projectFile = Util.GetSampleProject (dir, testFile); var p = new MSBuildProject (); p.Load (projectFile); p.Evaluate (); return p; }
public MSBuildProjectInstance (MSBuildProject project) { msproject = project; evaluatedItemsIgnoringCondition = new List<IMSBuildItemEvaluated> (); evaluatedProperties = new MSBuildEvaluatedPropertyCollection (msproject); if (!project.SolutionDirectory.IsNullOrEmpty) globalProperties.Add ("SolutionDir", project.SolutionDirectory.ToString ()); }
static MSBuildObject GetInsertBeforeObject (MSBuildProject project, ImportLocation importLocation) { if (importLocation == ImportLocation.Top) { return project.GetAllObjects ().FirstOrDefault (); } // Return an unknown MSBuildItem instead of null so the MSBuildProject adds the import as the last // child in the project. return new MSBuildItem (); }
void UpdateRequiresMSBuildSetting (MSBuildProject msproject, bool reloadProjectBuilder = false) { if (!RequiresMicrosoftBuild) { RequiresMicrosoftBuild = msproject.HasNuGetMetadata (); if (reloadProjectBuilder && RequiresMicrosoftBuild) { Project.ReloadProjectBuilder (); EnsureReferencedProjectsRequireMSBuild (reloadProjectBuilder); } } }
protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject msproject) { base.OnWriteProject (monitor, msproject); UpdateRequiresMSBuildSetting (msproject, true); if (InstallBuildPackagingNuGetAfterWrite) { InstallBuildPackagingNuGetAfterWrite = false; Project.InstallBuildPackagingNuGetPackage (); } }
public override object LoadProject (MSBuildProject p, string xml, FilePath fileName) { lock (engine) { engine.GlobalProperties.Clear (); var project = new MSProject (engine); project.BuildEnabled = false; project.FullFileName = fileName; project.LoadXml (xml); return project; } }
public override object LoadProject (MSBuildProject project, string xml, FilePath fileName) { var d = Environment.CurrentDirectory; Environment.CurrentDirectory = Path.GetDirectoryName (fileName); try { var p = projects.LoadProject (new XmlTextReader (new StringReader (xml))); p.FullPath = fileName; return p; } finally { Environment.CurrentDirectory = d; } }
public void UpdateProject (MSBuildProject project) { string importsRelativeDirectory = MSBuildProjectService.ToMSBuildPath (project.BaseDirectory, importsBaseDirectory); var importsToRemove = project.Imports.Where (import => IsMatch (import, importsRelativeDirectory)).ToList (); using (var updater = new EnsureNuGetPackageBuildImportsTargetUpdater ()) { foreach (MSBuildImport import in importsToRemove) { project.RemoveImport (import.Project); updater.RemoveImport (import.Project); updater.UpdateProject (project); } } }
public void UpdateProject (MSBuildProject msproject) { NuGetPackageForcedImportsRemover importsRemover = ForcedImportsRemover; if (importsRemover != null) { importsRemover.UpdateProject (msproject); } EnsureNuGetPackageBuildImportsTargetUpdater currentUpdater = Updater; if (currentUpdater != null) { currentUpdater.UpdateProject (msproject); } NuGetPackageNewImportsHandler importsHandler = NewImportsHandler; if (importsHandler != null) { importsHandler.UpdateProject (msproject); } }
void Load (MSBuildProject project) { MSBuildPropertyGroup propertyGroup = project.GetNuGetMetadataPropertyGroup (); Id = GetProperty (propertyGroup, PackageIdPropertyName); Version = GetProperty (propertyGroup, "PackageVersion"); Authors = GetProperty (propertyGroup, "Authors"); DevelopmentDependency = GetProperty (propertyGroup, "DevelopmentDependency", false); IconUrl = GetProperty (propertyGroup, "PackageIconUrl"); Language = GetProperty (propertyGroup, "NeutralLanguage"); LicenseUrl = GetProperty (propertyGroup, "PackageLicenseUrl"); Owners = GetProperty (propertyGroup, "Owners"); ProjectUrl = GetProperty (propertyGroup, "PackageProjectUrl"); ReleaseNotes = GetProperty (propertyGroup, "PackageReleaseNotes"); RequireLicenseAcceptance = GetProperty (propertyGroup, "PackageRequireLicenseAcceptance", false); Summary = GetProperty (propertyGroup, "Summary"); Tags = GetProperty (propertyGroup, "PackageTags"); Title = GetProperty (propertyGroup, "Title"); }
public void UpdateProject (MSBuildProject project) { if (importToRemove == null) return; MSBuildTarget nugetImportTarget = FindNuGetImportTarget (project); if (nugetImportTarget == null) return; MSBuildTask msbuildTask = FindErrorTaskForImport (nugetImportTarget, importToRemove); if (msbuildTask == null) return; nugetImportTarget.RemoveTask (msbuildTask); if (nugetImportTarget.Tasks.Count () == 0) { project.Remove (nugetImportTarget); } }
protected override void OnReadProject (ProgressMonitor monitor, MSBuildProject msproject) { base.OnReadProject (monitor, msproject); var import = msproject.Imports.FirstOrDefault (im => im.Label == "Shared"); if (import == null) return; // TODO: load the type from msbuild foreach (var item in msproject.Imports) { if (item.Project.Equals (CSharptargets, StringComparison.OrdinalIgnoreCase)) { LanguageName = "C#"; break; } if (item.Project.Equals (FSharptargets, StringComparison.OrdinalIgnoreCase)) { LanguageName = "F#"; break; } } //If for some reason the language name is empty default it to C# if (String.IsNullOrEmpty(LanguageName)) LanguageName = "C#"; projItemsPath = MSBuildProjectService.FromMSBuildPath (msproject.BaseDirectory, import.Project); MSBuildProject p = new MSBuildProject (msproject.EngineManager); p.Load (projItemsPath); p.Evaluate (); var cp = p.PropertyGroups.FirstOrDefault (g => g.Label == "Configuration"); if (cp != null) DefaultNamespace = cp.GetValue ("Import_RootNamespace"); LoadProjectItems (p, ProjectItemFlags.None, usedMSBuildItems); projitemsProject = p; }
internal protected override void OnReadProject (ProgressMonitor monitor, MSBuildProject msproject) { base.OnReadProject (monitor, msproject); // Convert .projitems imports into project references foreach (var sp in msproject.Imports.Where (im => im.Label == "Shared" && im.Project.EndsWith (".projitems"))) { var projitemsFile = sp.Project; if (!string.IsNullOrEmpty (projitemsFile)) { projitemsFile = MSBuildProjectService.FromMSBuildPath (Project.ItemDirectory, projitemsFile); projitemsFile = Path.Combine (Path.GetDirectoryName (msproject.FileName), projitemsFile); if (File.Exists (projitemsFile)) { using (MSBuildProject p = new MSBuildProject (msproject.EngineManager)) { p.Load (projitemsFile); Project.LoadProjectItems (p, ProjectItemFlags.Hidden | ProjectItemFlags.DontPersist, null); var r = ProjectReference.CreateProjectReference (projitemsFile); r.Flags = ProjectItemFlags.DontPersist; r.SetItemsProjectPath (projitemsFile); Project.References.Add (r); } } } } }
static bool HasOutputType(MSBuildProject project) { return(HasGlobalProperty(project, "OutputType")); }
public ProjectEvaluationException(MSBuildProject project, string message) : this(project, message, null) { }
protected override void OnWriteProject (ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) { if (projItemsPath == FilePath.Null) projItemsPath = Path.ChangeExtension (FileName, ".projitems"); if (projitemsProject == null) { projitemsProject = new MSBuildProject (msproject.EngineManager); projitemsProject.FileName = projItemsPath; var grp = projitemsProject.GetGlobalPropertyGroup (); if (grp == null) grp = projitemsProject.AddNewPropertyGroup (false); grp.SetValue ("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)"); grp.SetValue ("HasSharedItems", true); grp.SetValue ("SharedGUID", ItemId, preserveExistingCase:true); } IMSBuildPropertySet configGrp = projitemsProject.PropertyGroups.FirstOrDefault (g => g.Label == "Configuration"); if (configGrp == null) { configGrp = projitemsProject.AddNewPropertyGroup (true); configGrp.Label = "Configuration"; } configGrp.SetValue ("Import_RootNamespace", DefaultNamespace); base.OnWriteProject (monitor, msproject); var newProject = FileName == null || projitemsProject.IsNewProject; if (newProject) { var grp = msproject.GetGlobalPropertyGroup (); if (grp == null) grp = msproject.AddNewPropertyGroup (false); grp.SetValue ("ProjectGuid", ItemId, preserveExistingCase:true); var import = msproject.AddNewImport (@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"); import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"; msproject.AddNewImport (@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"); msproject.AddNewImport (@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props"); import = msproject.AddNewImport (MSBuildProjectService.ToMSBuildPath (FileName.ParentDirectory, projItemsPath)); import.Label = "Shared"; if (LanguageName.Equals("C#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport (CSharptargets); } else if (LanguageName.Equals("F#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport (FSharptargets); } } else { var itemsImport = msproject.Imports.FirstOrDefault (i => i.Label == "Shared"); if (itemsImport != null) itemsImport.Project = MSBuildProjectService.ToMSBuildPath (FileName.ParentDirectory, projItemsPath); else { var import = msproject.AddNewImport (MSBuildProjectService.ToMSBuildPath (FileName.ParentDirectory, projItemsPath)); import.Label = "Shared"; } } // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly if (ToolsVersion != "2.0") msproject.ToolsVersion = ToolsVersion; else if (string.IsNullOrEmpty (msproject.ToolsVersion)) msproject.ToolsVersion = null; else msproject.ToolsVersion = "2.0"; projitemsProject.Save (projItemsPath); }
internal override void SaveProjectItems (ProgressMonitor monitor, MSBuildProject msproject, HashSet<MSBuildItem> loadedItems, string pathPrefix) { // Save project items in the .projitems file base.SaveProjectItems (monitor, projitemsProject, usedMSBuildItems, "$(MSBuildThisFileDirectory)"); }
public MSBuildPropertyGroupMerged(MSBuildProject project) { ParentProject = project; }
public MSBuildEvaluatedPropertyCollection(MSBuildProject parent) : base(parent) { }
protected override void OnWriteProject(ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) { if (projItemsPath == FilePath.Null) { projItemsPath = Path.ChangeExtension(FileName, ".projitems"); } if (projitemsProject == null) { projitemsProject = new MSBuildProject(msproject.EngineManager); projitemsProject.FileName = projItemsPath; var grp = projitemsProject.GetGlobalPropertyGroup(); if (grp == null) { grp = projitemsProject.AddNewPropertyGroup(false); } grp.SetValue("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)"); grp.SetValue("HasSharedItems", true); grp.SetValue("SharedGUID", ItemId, preserveExistingCase: true); } IMSBuildPropertySet configGrp = projitemsProject.PropertyGroups.FirstOrDefault(g => g.Label == "Configuration"); if (configGrp == null) { configGrp = projitemsProject.AddNewPropertyGroup(true); configGrp.Label = "Configuration"; } configGrp.SetValue("Import_RootNamespace", DefaultNamespace); base.OnWriteProject(monitor, msproject); var newProject = FileName == null || !File.Exists(FileName); if (newProject) { var grp = msproject.GetGlobalPropertyGroup(); if (grp == null) { grp = msproject.AddNewPropertyGroup(false); } grp.SetValue("ProjectGuid", ItemId, preserveExistingCase: true); var import = msproject.AddNewImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"); import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"; msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"); msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props"); import = msproject.AddNewImport(Path.ChangeExtension(FileName.FileName, ".projitems")); import.Label = "Shared"; if (LanguageName.Equals("C#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport(CSharptargets); } else if (LanguageName.Equals("F#", StringComparison.OrdinalIgnoreCase)) { msproject.AddNewImport(FSharptargets); } } else { msproject.Load(FileName); } // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly if (ToolsVersion != "2.0") { msproject.ToolsVersion = ToolsVersion; } else if (string.IsNullOrEmpty(msproject.ToolsVersion)) { msproject.ToolsVersion = null; } else { msproject.ToolsVersion = "2.0"; } projitemsProject.Save(projItemsPath); }
internal void ResetIndent (bool closeInNewLine, MSBuildProject project, MSBuildObject parent, MSBuildNode previousSibling) { StartInnerWhitespace = StartWhitespace = EndWhitespace = EndInnerWhitespace = null; if (previousSibling != null) { StartWhitespace = previousSibling.StartWhitespace; if (closeInNewLine) EndInnerWhitespace = StartWhitespace; } else if (parent != null) { if (parent.StartInnerWhitespace == null) { parent.StartInnerWhitespace = project.TextFormat.NewLine; parent.EndInnerWhitespace = parent.StartWhitespace; } object parentStartWhitespace = (parent != project) ? parent.StartWhitespace : ""; StartWhitespace = parentStartWhitespace + " "; if (closeInNewLine) EndInnerWhitespace = StartWhitespace; } EndWhitespace = project.TextFormat.NewLine; if (closeInNewLine) StartInnerWhitespace = project.TextFormat.NewLine; ResetChildrenIndent (); }
public MSBuildEvaluationContext (MSBuildEvaluationContext parentContext) { this.parentContext = parentContext; this.project = parentContext.project; }
public abstract object LoadProject(MSBuildProject project, string xml, FilePath fileName);
internal void InitEvaluation(MSBuildProject project) { this.project = project; // Project file properties properties.Add("MSBuildThisFile", Path.GetFileName(project.FileName)); properties.Add("MSBuildThisFileName", project.FileName.FileNameWithoutExtension); properties.Add("MSBuildThisFileExtension", Path.GetExtension(project.FileName)); properties.Add("MSBuildThisFileFullPath", MSBuildProjectService.ToMSBuildPath(null, project.FileName.FullPath)); string dir = Path.GetDirectoryName(project.FileName) + Path.DirectorySeparatorChar; properties.Add("MSBuildThisFileDirectory", MSBuildProjectService.ToMSBuildPath(null, dir)); properties.Add("MSBuildThisFileDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath(null, dir.Substring(Path.GetPathRoot(dir).Length))); // Properties only set for the root project, not for imported projects if (parentContext == null) { properties.Add("VisualStudioReferenceAssemblyVersion", project.ToolsVersion + ".0.0"); properties.Add("MSBuildProjectDefaultTargets", project.DefaultTargets); properties.Add("MSBuildProjectExtension", Path.GetExtension(project.FileName)); properties.Add("MSBuildProjectFile", project.FileName.FileName); properties.Add("MSBuildProjectFullPath", MSBuildProjectService.ToMSBuildPath(null, project.FileName.FullPath.ToString())); properties.Add("MSBuildProjectName", project.FileName.FileNameWithoutExtension); dir = project.BaseDirectory.IsNullOrEmpty ? Environment.CurrentDirectory : project.BaseDirectory.ToString(); properties.Add("MSBuildProjectDirectory", MSBuildProjectService.ToMSBuildPath(null, dir)); properties.Add("MSBuildProjectDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath(null, dir.Substring(Path.GetPathRoot(dir).Length))); // This MSBuild loader is v15.0 string toolsVersion = "15.0"; properties.Add("MSBuildAssemblyVersion", "15.0"); var toolsPath = Runtime.SystemAssemblyService.DefaultRuntime.GetMSBuildToolsPath(toolsVersion); var frameworkToolsPath = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.VersionLatest); properties.Add("MSBuildBinPath", MSBuildProjectService.ToMSBuildPath(null, toolsPath)); properties.Add("MSBuildToolsPath", MSBuildProjectService.ToMSBuildPath(null, toolsPath)); properties.Add("MSBuildToolsRoot", MSBuildProjectService.ToMSBuildPath(null, Path.GetDirectoryName(toolsPath))); properties.Add("MSBuildToolsVersion", toolsVersion); properties.Add("OS", Platform.IsWindows ? "Windows_NT" : "Unix"); properties.Add("MSBuildBinPath32", MSBuildProjectService.ToMSBuildPath(null, toolsPath)); properties.Add("MSBuildFrameworkToolsPath", MSBuildProjectService.ToMSBuildPath(null, frameworkToolsPath)); properties.Add("MSBuildFrameworkToolsPath32", MSBuildProjectService.ToMSBuildPath(null, frameworkToolsPath)); if (Platform.IsWindows) { // Taken from MSBuild source: var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); var programFiles32 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); if (string.IsNullOrEmpty(programFiles32)) { programFiles32 = programFiles; // 32 bit box } string programFiles64; if (programFiles == programFiles32) { // either we're in a 32-bit window, or we're on a 32-bit machine. // if we're on a 32-bit machine, ProgramW6432 won't exist // if we're on a 64-bit machine, ProgramW6432 will point to the correct Program Files. programFiles64 = Environment.GetEnvironmentVariable("ProgramW6432"); } else { // 64-bit window on a 64-bit machine; %ProgramFiles% points to the 64-bit // Program Files already. programFiles64 = programFiles; } var extensionsPath32 = MSBuildProjectService.ToMSBuildPath(null, Path.Combine(programFiles32, "MSBuild")); properties.Add("MSBuildExtensionsPath32", extensionsPath32); if (programFiles64 != null) { properties.Add("MSBuildExtensionsPath64", MSBuildProjectService.ToMSBuildPath(null, Path.Combine(programFiles64, "MSBuild"))); } // MSBuildExtensionsPath: The way this used to work is that it would point to "Program Files\MSBuild" on both // 32-bit and 64-bit machines. We have a switch to continue using that behavior; however the default is now for // MSBuildExtensionsPath to always point to the same location as MSBuildExtensionsPath32. bool useLegacyMSBuildExtensionsPathBehavior = !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILDLEGACYEXTENSIONSPATH")); string extensionsPath; if (useLegacyMSBuildExtensionsPathBehavior) { extensionsPath = Path.Combine(programFiles, "MSBuild"); } else { extensionsPath = extensionsPath32; } properties.Add("MSBuildExtensionsPath", extensionsPath); } else if (!String.IsNullOrEmpty(DefaultExtensionsPath)) { var ep = MSBuildProjectService.ToMSBuildPath(null, extensionsPath); properties.Add("MSBuildExtensionsPath", ep); properties.Add("MSBuildExtensionsPath32", ep); properties.Add("MSBuildExtensionsPath64", ep); } // Environment properties.Add("MSBuildProgramFiles32", MSBuildProjectService.ToMSBuildPath(null, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86))); } }
internal void InitEvaluation(MSBuildProject project) { this.project = project; // Project file properties properties.Add("MSBuildThisFile", Path.GetFileName(project.FileName)); properties.Add("MSBuildThisFileName", project.FileName.FileNameWithoutExtension); properties.Add("MSBuildThisFileExtension", Path.GetExtension(project.FileName)); properties.Add("MSBuildThisFileFullPath", MSBuildProjectService.ToMSBuildPath(null, project.FileName.FullPath)); string dir = Path.GetDirectoryName(project.FileName) + Path.DirectorySeparatorChar; properties.Add("MSBuildThisFileDirectory", MSBuildProjectService.ToMSBuildPath(null, dir)); properties.Add("MSBuildThisFileDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath(null, dir.Substring(Path.GetPathRoot(dir).Length))); // Properties only set for the root project, not for imported projects if (parentContext == null) { properties.Add("VisualStudioReferenceAssemblyVersion", project.ToolsVersion + ".0.0"); properties.Add("MSBuildProjectDefaultTargets", project.DefaultTargets); properties.Add("MSBuildProjectExtension", Path.GetExtension(project.FileName)); properties.Add("MSBuildProjectFile", project.FileName.FileName); properties.Add("MSBuildProjectFullPath", MSBuildProjectService.ToMSBuildPath(null, project.FileName.FullPath.ToString())); properties.Add("MSBuildProjectName", project.FileName.FileNameWithoutExtension); dir = project.BaseDirectory.IsNullOrEmpty ? Environment.CurrentDirectory : project.BaseDirectory.ToString(); properties.Add("MSBuildProjectDirectory", MSBuildProjectService.ToMSBuildPath(null, dir)); properties.Add("MSBuildProjectDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath(null, dir.Substring(Path.GetPathRoot(dir).Length))); string toolsVersion = project.ToolsVersion; if (string.IsNullOrEmpty(toolsVersion) || Version.Parse(toolsVersion) < new Version("12.0")) { toolsVersion = "12.0"; } string toolsPath = ToolLocationHelper.GetPathToBuildTools("12.0"); var frameworkToolsPath = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.VersionLatest); properties.Add("MSBuildBinPath", MSBuildProjectService.ToMSBuildPath(null, toolsPath)); properties.Add("MSBuildToolsPath", MSBuildProjectService.ToMSBuildPath(null, toolsPath)); properties.Add("MSBuildToolsRoot", MSBuildProjectService.ToMSBuildPath(null, Path.GetDirectoryName(toolsPath))); properties.Add("MSBuildToolsVersion", toolsVersion); properties.Add("OS", Platform.IsWindows ? "Windows_NT" : "Unix"); properties.Add("MSBuildBinPath32", MSBuildProjectService.ToMSBuildPath(null, toolsPath)); properties.Add("MSBuildFrameworkToolsPath", MSBuildProjectService.ToMSBuildPath(null, frameworkToolsPath)); properties.Add("MSBuildFrameworkToolsPath32", MSBuildProjectService.ToMSBuildPath(null, frameworkToolsPath)); if (!String.IsNullOrEmpty(DefaultExtensionsPath)) { var ep = MSBuildProjectService.ToMSBuildPath(null, extensionsPath); properties.Add("MSBuildExtensionsPath", ep); properties.Add("MSBuildExtensionsPath32", ep); properties.Add("MSBuildExtensionsPath64", ep); } // Environment properties.Add("MSBuildProgramFiles32", MSBuildProjectService.ToMSBuildPath(null, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86))); } }
public MSBuildEvaluationContext(MSBuildEvaluationContext parentContext) { this.parentContext = parentContext; this.project = parentContext.project; }
internal static async Task MigrateFlavors (ProgressMonitor monitor, string fileName, string typeGuid, MSBuildProject p, List<SolutionItemExtensionNode> nodes) { var language = GetLanguageFromGuid (typeGuid); bool migrated = false; foreach (var node in nodes) { if (await MigrateProject (monitor, node, p, fileName, language)) migrated = true; } if (migrated) await p.SaveAsync (fileName); }
internal ProjectEvaluationException(MSBuildProject project, string message, Exception innerException) : base(message, innerException) { Project = project; }
public async Task <AssemblyReference[]> ResolveAssemblyReferences(ProjectConfigurationInfo[] configurations, Dictionary <string, string> globalProperties, MSBuildProject project, CancellationToken cancellationToken) { AssemblyReference[] refs = null; var id = configurations [0].Configuration + "|" + configurations [0].Platform; using (await referenceCacheLock.EnterAsync().ConfigureAwait(false)) { // Check the cache before starting the task if (referenceCache.TryGetValue(id, out refs)) { return(refs); } // Get an id for the task, it will be used later on to cancel the task if necessary var taskId = Interlocked.Increment(ref lastTaskId); IDisposable cr = RegisterCancellation(cancellationToken, taskId); MSBuildResult result; try { BeginOperation(); result = await builder.Run( configurations, -1, MSBuildEvent.None, MSBuildVerbosity.Quiet, new [] { "ResolveAssemblyReferences" }, new [] { "ReferencePath" }, null, globalProperties, taskId ).ConfigureAwait(false); } catch (Exception ex) { await CheckDisconnected().ConfigureAwait(false); LoggingService.LogError("ResolveAssemblyReferences failed", ex); return(new AssemblyReference [0]); } finally { cr.Dispose(); EndOperation(); } MSBuildEvaluatedItem[] items; if (result.Items.TryGetValue("ReferencePath", out items) && items != null) { refs = items.Select(it => CreateAssemblyReference(it, project)).ToArray(); } else { refs = new AssemblyReference [0]; } referenceCache [id] = refs; } return(refs); }
internal MSBuildPropertyGroupEvaluated(MSBuildProject parent) { ParentProject = parent; }
public ProjectEvaluationException(MSBuildProject project, string message) : base(message) { Project = project; }
MSBuildProject CreateMSBuildProject (string xml) { var msbuildProject = new MSBuildProject (); msbuildProject.LoadXml (xml); return msbuildProject; }
internal MSBuildPropertyGroupEvaluated(MSBuildProject parent) { this.parent = parent; }
internal void InitEvaluation (MSBuildProject project) { this.project = project; // Project file properties properties.Add ("MSBuildThisFile", Path.GetFileName (project.FileName)); properties.Add ("MSBuildThisFileName", project.FileName.FileNameWithoutExtension); properties.Add ("MSBuildThisFileExtension", Path.GetExtension (project.FileName)); properties.Add ("MSBuildThisFileFullPath", MSBuildProjectService.ToMSBuildPath (null, project.FileName.FullPath)); string dir = Path.GetDirectoryName (project.FileName) + Path.DirectorySeparatorChar; properties.Add ("MSBuildThisFileDirectory", MSBuildProjectService.ToMSBuildPath (null, dir)); properties.Add ("MSBuildThisFileDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath (null, dir.Substring (Path.GetPathRoot (dir).Length))); // Properties only set for the root project, not for imported projects if (parentContext == null) { properties.Add ("VisualStudioReferenceAssemblyVersion", project.ToolsVersion + ".0.0"); properties.Add ("MSBuildProjectDefaultTargets", project.DefaultTargets); properties.Add ("MSBuildProjectExtension", Path.GetExtension (project.FileName)); properties.Add ("MSBuildProjectFile", project.FileName.FileName); properties.Add ("MSBuildProjectFullPath", MSBuildProjectService.ToMSBuildPath (null, project.FileName.FullPath.ToString())); properties.Add ("MSBuildProjectName", project.FileName.FileNameWithoutExtension); dir = project.BaseDirectory.IsNullOrEmpty ? Environment.CurrentDirectory : project.BaseDirectory.ToString(); properties.Add ("MSBuildProjectDirectory", MSBuildProjectService.ToMSBuildPath (null, dir)); properties.Add ("MSBuildProjectDirectoryNoRoot", MSBuildProjectService.ToMSBuildPath (null, dir.Substring (Path.GetPathRoot (dir).Length))); string toolsVersion = project.ToolsVersion; if (string.IsNullOrEmpty (toolsVersion) || Version.Parse (toolsVersion) < new Version ("12.0")) toolsVersion = "12.0"; string toolsPath = ToolLocationHelper.GetPathToBuildTools ("12.0"); var frameworkToolsPath = ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.VersionLatest); properties.Add ("MSBuildBinPath", MSBuildProjectService.ToMSBuildPath (null, toolsPath)); properties.Add ("MSBuildToolsPath", MSBuildProjectService.ToMSBuildPath (null, toolsPath)); properties.Add ("MSBuildToolsRoot", MSBuildProjectService.ToMSBuildPath (null, Path.GetDirectoryName (toolsPath))); properties.Add ("MSBuildToolsVersion", toolsVersion); properties.Add ("OS", Platform.IsWindows ? "Windows_NT" : "Unix"); properties.Add ("MSBuildBinPath32", MSBuildProjectService.ToMSBuildPath (null, toolsPath)); properties.Add ("MSBuildFrameworkToolsPath", MSBuildProjectService.ToMSBuildPath (null, frameworkToolsPath)); properties.Add ("MSBuildFrameworkToolsPath32", MSBuildProjectService.ToMSBuildPath (null, frameworkToolsPath)); if (Platform.IsWindows) { // Taken from MSBuild source: var programFiles = Environment.GetFolderPath (Environment.SpecialFolder.ProgramFiles); var programFiles32 = Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86); if (string.IsNullOrEmpty(programFiles32)) programFiles32 = programFiles; // 32 bit box string programFiles64; if (programFiles == programFiles32) { // either we're in a 32-bit window, or we're on a 32-bit machine. // if we're on a 32-bit machine, ProgramW6432 won't exist // if we're on a 64-bit machine, ProgramW6432 will point to the correct Program Files. programFiles64 = Environment.GetEnvironmentVariable("ProgramW6432"); } else { // 64-bit window on a 64-bit machine; %ProgramFiles% points to the 64-bit // Program Files already. programFiles64 = programFiles; } var extensionsPath32 = MSBuildProjectService.ToMSBuildPath (null, Path.Combine (programFiles32, "MSBuild")); properties.Add ("MSBuildExtensionsPath32", extensionsPath32); if (programFiles64 != null) properties.Add ("MSBuildExtensionsPath64", MSBuildProjectService.ToMSBuildPath (null, Path.Combine(programFiles64, "MSBuild"))); // MSBuildExtensionsPath: The way this used to work is that it would point to "Program Files\MSBuild" on both // 32-bit and 64-bit machines. We have a switch to continue using that behavior; however the default is now for // MSBuildExtensionsPath to always point to the same location as MSBuildExtensionsPath32. bool useLegacyMSBuildExtensionsPathBehavior = !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILDLEGACYEXTENSIONSPATH")); string extensionsPath; if (useLegacyMSBuildExtensionsPathBehavior) extensionsPath = Path.Combine (programFiles, "MSBuild"); else extensionsPath = extensionsPath32; properties.Add ("MSBuildExtensionsPath", extensionsPath); } else if (!String.IsNullOrEmpty (DefaultExtensionsPath)) { var ep = MSBuildProjectService.ToMSBuildPath (null, extensionsPath); properties.Add ("MSBuildExtensionsPath", ep); properties.Add ("MSBuildExtensionsPath32", ep); properties.Add ("MSBuildExtensionsPath64", ep); } // Environment properties.Add ("MSBuildProgramFiles32", MSBuildProjectService.ToMSBuildPath (null, Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86))); } }
static IEnumerable <MSBuildItemEvaluated> ExpandWildcardFilePath(ProjectInfo pinfo, MSBuildProject project, MSBuildEvaluationContext context, MSBuildItem sourceItem, FilePath basePath, FilePath baseRecursiveDir, bool recursive, string[] filePath, int index) { var res = Enumerable.Empty <MSBuildItemEvaluated> (); if (index >= filePath.Length) { return(res); } var path = filePath [index]; if (path == "..") { return(ExpandWildcardFilePath(pinfo, project, context, sourceItem, basePath.ParentDirectory, baseRecursiveDir, recursive, filePath, index + 1)); } if (path == ".") { return(ExpandWildcardFilePath(pinfo, project, context, sourceItem, basePath, baseRecursiveDir, recursive, filePath, index + 1)); } if (!Directory.Exists(basePath)) { return(res); } if (path == "**") { // if this is the last component of the path, there isn't any file specifier, so there is no possible match if (index + 1 >= filePath.Length) { return(res); } // If baseRecursiveDir has already been set, don't overwrite it. if (baseRecursiveDir.IsNullOrEmpty) { baseRecursiveDir = basePath; } return(ExpandWildcardFilePath(pinfo, project, context, sourceItem, basePath, baseRecursiveDir, true, filePath, index + 1)); } if (recursive) { // Recursive search. Try to match the remaining subpath in all subdirectories. foreach (var dir in Directory.GetDirectories(basePath)) { res = res.Concat(ExpandWildcardFilePath(pinfo, project, context, sourceItem, dir, baseRecursiveDir, true, filePath, index)); } } if (index == filePath.Length - 1) { // Last path component. It has to be a file specifier. string baseDir = basePath.ToRelative(project.BaseDirectory).ToString().Replace('/', '\\'); if (baseDir == ".") { baseDir = ""; } else if (!baseDir.EndsWith("\\", StringComparison.Ordinal)) { baseDir += '\\'; } var recursiveDir = baseRecursiveDir.IsNullOrEmpty ? FilePath.Null : basePath.ToRelative(baseRecursiveDir); res = res.Concat(Directory.GetFiles(basePath, path).Select(f => { context.SetItemContext(f, recursiveDir); var ev = baseDir + Path.GetFileName(f); return(CreateEvaluatedItem(context, pinfo, project, sourceItem, ev)); })); } else { // Directory specifier // Look for matching directories. // The search here is non-recursive, not matter what the 'recursive' parameter says, since we are trying to match a subpath. // The recursive search is done below. if (path.IndexOfAny(wildcards) != -1) { foreach (var dir in Directory.GetDirectories(basePath, path)) { res = res.Concat(ExpandWildcardFilePath(pinfo, project, context, sourceItem, dir, baseRecursiveDir, false, filePath, index + 1)); } } else { res = res.Concat(ExpandWildcardFilePath(pinfo, project, context, sourceItem, basePath.Combine(path), baseRecursiveDir, false, filePath, index + 1)); } } return(res); }
public ProjectEvaluationException (MSBuildProject project, string message): base (message) { Project = project; }
static MSBuildItemEvaluated CreateEvaluatedItem(MSBuildEvaluationContext context, ProjectInfo pinfo, MSBuildProject project, MSBuildItem sourceItem, string include) { var it = new MSBuildItemEvaluated(project, sourceItem.Name, sourceItem.Include, include); var md = new Dictionary <string, IMSBuildPropertyEvaluated> (); foreach (var c in sourceItem.Metadata.GetProperties()) { if (string.IsNullOrEmpty(c.Condition) || SafeParseAndEvaluate(pinfo, context, c.Condition, true)) { md [c.Name] = new MSBuildPropertyEvaluated(project, c.Name, c.Value, context.EvaluateString(c.Value)); } } ((MSBuildPropertyGroupEvaluated)it.Metadata).SetProperties(md); it.SourceItem = sourceItem; it.Condition = sourceItem.Condition; return(it); }
public abstract object LoadProject (MSBuildProject project, string xml, FilePath fileName);
public override object LoadProject(MSBuildProject project, string xml, FilePath fileName) { return(project); }
static async Task<bool> MigrateProject (ProgressMonitor monitor, SolutionItemExtensionNode st, MSBuildProject p, string fileName, string language) { var projectLoadMonitor = GetProjectLoadProgressMonitor (monitor); if (projectLoadMonitor == null) { // projectLoadMonitor will be null when running through md-tool, but // this is not fatal if migration is not required, so just ignore it. --abock if (!st.IsMigrationRequired) return false; LoggingService.LogError (Environment.StackTrace); monitor.ReportError ("Could not open unmigrated project and no migrator was supplied", null); throw new UserException ("Project migration failed"); } var migrationType = st.MigrationHandler.CanPromptForMigration ? await st.MigrationHandler.PromptForMigration (projectLoadMonitor, p, fileName, language) : projectLoadMonitor.ShouldMigrateProject (); if (migrationType == MigrationType.Ignore) { if (st.IsMigrationRequired) { monitor.ReportError (string.Format ("{1} cannot open the project '{0}' unless it is migrated.", Path.GetFileName (fileName), BrandingService.ApplicationName), null); throw new UserException ("The user choose not to migrate the project"); } else return false; } var baseDir = (FilePath) Path.GetDirectoryName (fileName); if (migrationType == MigrationType.BackupAndMigrate) { var backupDirFirst = baseDir.Combine ("backup"); string backupDir = backupDirFirst; int i = 0; while (Directory.Exists (backupDir)) { backupDir = backupDirFirst + "-" + i.ToString (); if (i++ > 20) { throw new Exception ("Too many backup directories"); } } Directory.CreateDirectory (backupDir); foreach (var file in st.MigrationHandler.FilesToBackup (fileName)) File.Copy (file, Path.Combine (backupDir, Path.GetFileName (file))); } if (!await st.MigrationHandler.Migrate (projectLoadMonitor, p, fileName, language)) throw new UserException ("Project migration failed"); return true; }
protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject msproject) { base.OnWriteProject (monitor, msproject); var moniker = TargetFramework.Id; bool supportsMultipleFrameworks = true; // All supported formats support multiple frameworks. // toolsFormat.SupportsMonikers || toolsFormat.SupportedFrameworks.Length > 0; var def = GetDefaultTargetFrameworkForFormat (ToolsVersion); IMSBuildPropertySet globalGroup = msproject.GetGlobalPropertyGroup (); // If the format only supports one fx version, or the version is the default, there is no need to store it. // However, is there is already a value set, do not remove it. if (supportsMultipleFrameworks) { globalGroup.SetValue ("TargetFrameworkVersion", "v" + moniker.Version, "v" + def.Version, true); } if (MSBuildFileFormat.ToolsSupportMonikers (ToolsVersion)) { globalGroup.SetValue ("TargetFrameworkIdentifier", moniker.Identifier, def.Identifier, true); globalGroup.SetValue ("TargetFrameworkProfile", moniker.Profile, def.Profile, true); } }