/// <summary> /// Initializes a new instance of the <see cref="ResolvedImport"/> struct. /// </summary> internal ResolvedImport(Project project, ProjectImportElement importingElement, ProjectRootElement importedProject) { ErrorUtilities.VerifyThrowInternalNull(importingElement, "parent"); ErrorUtilities.VerifyThrowInternalNull(importedProject, "child"); _importingElement = importingElement; _importedProject = importedProject; _isImported = !ReferenceEquals(project.Xml, importingElement.ContainingProject); }
/// <summary> /// Creates an unparented ProjectImportElement, wrapping an unparented XmlElement. /// Validates the project value. /// Caller should then ensure the element is added to a parent /// </summary> internal static ProjectImportElement CreateDisconnected(string project, ProjectRootElement containingProject) { XmlElementWithLocation element = containingProject.CreateElement(XMakeElements.import); ProjectImportElement import = new ProjectImportElement(element, containingProject); import.Project = project; return import; }
/// <summary> /// Creates an unparented ProjectImportElement, wrapping an unparented XmlElement. /// Validates the project value. /// Caller should then ensure the element is added to a parent /// </summary> internal static ProjectImportElement CreateDisconnected(string project, ProjectRootElement containingProject) { XmlElementWithLocation element = containingProject.CreateElement(XMakeElements.import); ProjectImportElement import = new ProjectImportElement(element, containingProject); import.Project = project; return(import); }
public ProjectImportElement AddImport(string project) { ErrorUtilities.VerifyThrowArgumentLength(project, nameof(project)); ProjectImportElement newImport = ContainingProject.CreateImportElement(project); AppendChild(newImport); return(newImport); }
/// <summary> /// Creates an implicit ProjectImportElement as if it was in the project. /// </summary> /// <returns></returns> internal static ProjectImportElement CreateImplicit(string project, ProjectRootElement containingProject, ImplicitImportLocation implicitImportLocation, string sdkName) { ProjectImportElement import = CreateDisconnected(project, containingProject); import.ImplicitImportLocation = implicitImportLocation; import.Sdk = sdkName; return(import); }
/// <summary> /// Parse a ProjectImportGroupElement /// </summary> /// <param name="element">The XML element to parse</param> /// <param name="parent">The parent <see cref="ProjectRootElement"/>.</param> /// <returns>A ProjectImportGroupElement derived from the XML element passed in</returns> private ProjectImportGroupElement ParseProjectImportGroupElement(XmlElementWithLocation element, ProjectRootElement parent) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel); ProjectImportGroupElement importGroup = new ProjectImportGroupElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectErrorUtilities.VerifyThrowInvalidProject ( childElement.Name == XMakeElements.import, childElement.Location, "UnrecognizedChildElement", childElement.Name, element.Name ); ProjectImportElement item = ParseProjectImportElement(childElement, importGroup); importGroup.AppendParentedChildNoChecks(item); } return(importGroup); }
public void SetProjectType([NotNull] string type) { if (_projectTypeImport == null) { _projectTypeImport = RootElement.Imports.OrderBy(imp => imp.ProjectLocation.Line).ElementAtOrDefault(1); if (_projectTypeImport != null) return; _projectTypeImport = RootElement.AddImport(type); return; } _projectTypeImport.Project = type; }
/// <summary> /// Check if the Import element has a repair pattern: /// $(MSBuildExtensionsPath)\Microsoft\VisualStudio\vX.X /// or $(MSBuildExtensionsPath)\Microsoft.VisualStudio.OfficeTools.targets /// </summary> /// <param name="importElement"></param> /// <returns></returns> private bool HasRepairPattern(ProjectImportElement importElement) { bool bHasRepairPattern = false; // in case of an already repaired project the repair pattern will exist with Condition="false" if (!String.Equals(importElement.Condition, "false", StringComparison.OrdinalIgnoreCase)) { if ((importElement.Project.StartsWith(XMakeProjectStrings.toRepairPatternForAssetCompat, StringComparison.OrdinalIgnoreCase)) || (importElement.Project.StartsWith(XMakeProjectStrings.toRepairPatternForAssetCompatBeforeV10, StringComparison.OrdinalIgnoreCase))) { string startString; if (importElement.Project.StartsWith(XMakeProjectStrings.toRepairPatternForAssetCompat, StringComparison.OrdinalIgnoreCase)) { startString = XMakeProjectStrings.toRepairPatternForAssetCompat; } else { startString = XMakeProjectStrings.toRepairPatternForAssetCompatBeforeV10; } Match m = Regex.Match(importElement.Project.Substring(startString.Length), XMakeProjectStrings.repairHardCodedPathPattern); if (m.Success) { bHasRepairPattern = true; } } else { // Check for VS2003/2005 Office Targets // $(MSBuildExtensionsPath)\Microsoft.VisualStudio.OfficeTools.targets if (importElement.Project.Equals(XMakeProjectStrings.officeTargetsVS2005Import, StringComparison.OrdinalIgnoreCase) || importElement.Project.Equals(XMakeProjectStrings.officeTargetsVS2005Import2, StringComparison.OrdinalIgnoreCase)) bHasRepairPattern = true; } } return bHasRepairPattern; }
/// <summary> /// Repairs the given import element /// Change Import to use $(VSToolsPath), with Condition using $(VSToolsPath) /// e.g. From: Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /// To: Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" /// Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" /// $(VSToolsPath) will be defined elsewhere in this upgrade to be: $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) /// </summary> /// <param name="toRepairImport"></param> private void RepairImportForAssetCompat(ProjectImportElement toRepairImport) { // We shouldn't have this happen but check anyway: ErrorUtilities.VerifyThrowInternalNull(toRepairImport, "toRepairImport"); ErrorUtilities.VerifyThrow(!toRepairImport.Condition.Equals("false", StringComparison.OrdinalIgnoreCase), "RepairImportForAssetCompat should not receive imports with condition=false already"); var newImportElement = this.xmakeProject.CreateImportElement(toRepairImport.Project); newImportElement.Condition = "false"; newImportElement.Project = XMakeProjectStrings.toRepairPatternForAssetCompatV10 + ExtractImportTargetsString(newImportElement.Project); toRepairImport.Parent.InsertAfterChild(newImportElement, toRepairImport); toRepairImport.Project = @"$(VSToolsPath)\" + ExtractImportTargetsString(toRepairImport.Project); toRepairImport.Condition = @"'$(VSToolsPath)' != ''"; }
internal ResolvedImport (ProjectImportElement import, ProjectRootElement root, bool isImported) { this.import = import; this.root = root; this.imported = isImported; }