コード例 #1
0
		public MSBuildBasedProject(MSBuild.Engine engine)
		{
			if (engine == null)
				throw new ArgumentNullException("engine");
			this.project = engine.CreateNewProject();
			this.userProject = engine.CreateNewProject();
		}
コード例 #2
0
        /// <summary>
        /// Overloaded constructor.
        /// </summary>
        /// <param name="project">An instance of a build project</param>
        /// <exception cref="ArgumentNullException">Is thrown if the passed Project is null.</exception>
        internal GlobalPropertyHandler(MSBuild.Project project)
        {
            Debug.Assert(project != null, "The project parameter passed cannot be null");

            this.globalProjectProperties = project.GlobalProperties;

            Debug.Assert(project.ParentEngine != null, "The parent engine has not been initialized");

            this.globalEngineProperties = project.ParentEngine.GlobalProperties;
        }
コード例 #3
0
		internal static void AddItemToGroup(MSBuild.BuildItemGroup group, ProjectItem item)
		{
			if (group == null)
				throw new ArgumentNullException("group");
			if (item == null)
				throw new ArgumentNullException("item");
			if (item.IsAddedToProject)
				throw new ArgumentException("item is already added to project", "item");
			MSBuild.BuildItem newItem = group.AddNewItem(item.ItemType.ToString(), item.Include, true);
			foreach (string name in item.MetadataNames) {
				newItem.SetMetadata(name, item.GetMetadata(name));
			}
			item.BuildItem = newItem;
			Debug.Assert(item.IsAddedToProject);
		}
コード例 #4
0
ファイル: projectelement.cs プロジェクト: Jeremiahf/wix3
        /// <summary>
        /// Constructor to Wrap an existing MSBuild.BuildItem
        /// Only have internal constructors as the only one who should be creating
        /// such object is the project itself (see Project.CreateFileNode()).
        /// </summary>
        /// <param name="project">Project that owns this item</param>
        /// <param name="existingItem">an MSBuild.BuildItem; can be null if virtualFolder is true</param>
        /// <param name="virtualFolder">Is this item virtual (such as reference folder)</param>
        internal ProjectElement(ProjectNode project, MSBuild.BuildItem existingItem, bool virtualFolder)
        {
            if (project == null)
                throw new ArgumentNullException("project");
            if (!virtualFolder && existingItem == null)
                throw new ArgumentNullException("existingItem");

            // Keep a reference to project and item
            this.itemProject = project;
            this.item = existingItem;
            this.isVirtual = virtualFolder;

            if (this.isVirtual)
                this.virtualProperties = new Dictionary<string, string>();
        }
コード例 #5
0
ファイル: ProjectElement.cs プロジェクト: Xtremrules/dot42
        /// <summary>
        /// Constructor to Wrap an existing MSBuild.BuildItem
        /// Only have internal constructors as the only one who should be creating
        /// such object is the project itself (see Project.CreateFileNode()).
        /// </summary>
        /// <param name="project">Project that owns this item</param>
        /// <param name="existingItem">an MSBuild.BuildItem; can be null if virtualFolder is true</param>
        /// <param name="virtualFolder">Is this item virtual (such as reference folder)</param>
        internal ProjectElement(ProjectNode project, MSBuild.BuildItem existingItem, bool virtualFolder)
        {
            if (project == null)
                throw new ArgumentNullException("project", String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.AddToNullProjectError), existingItem.Include));
            if (!virtualFolder && existingItem == null)
                throw new ArgumentNullException("existingItem");

            // Keep a reference to project and item
            itemProject = project;
            item = existingItem;
            isVirtual = virtualFolder;

            if (isVirtual)
                virtualProperties = new Dictionary<string, string>();
        }
コード例 #6
0
		internal static void EnsureCorrectTempProject(MSBuild.Project baseProject,
		                                              string configuration, string platform,
		                                              ref MSBuild.Project tempProject)
		{
			if (configuration == null && platform == null) {
				// unload temp project
				if (tempProject != null && tempProject != baseProject) {
					tempProject.ParentEngine.UnloadAllProjects();
				}
				tempProject = null;
				return;
			}
			if (configuration == null)
				configuration = baseProject.GetEvaluatedProperty("Configuration");
			if (platform == null)
				platform = baseProject.GetEvaluatedProperty("Platform");
			
			if (tempProject != null
			    && tempProject.GetEvaluatedProperty("Configuration") == configuration
			    && tempProject.GetEvaluatedProperty("Platform") == platform)
			{
				// already correct
				return;
			}
			if (baseProject.GetEvaluatedProperty("Configuration") == configuration
			    && baseProject.GetEvaluatedProperty("Platform") == platform)
			{
				tempProject = baseProject;
				return;
			}
			// create new project
			
			// unload old temp project
			if (tempProject != null && tempProject != baseProject) {
				tempProject.ParentEngine.UnloadAllProjects();
			}
			try {
				MSBuild.Engine engine = CreateEngine();
				tempProject = engine.CreateNewProject();
				MSBuildBasedProject.InitializeMSBuildProject(tempProject);
				tempProject.LoadXml(baseProject.Xml);
				tempProject.SetProperty("Configuration", configuration);
				tempProject.SetProperty("Platform", platform);
			} catch (Exception ex) {
				ICSharpCode.Core.MessageService.ShowWarning(ex.ToString());
				tempProject = baseProject;
			}
		}
コード例 #7
0
		/// <summary>
		/// Creates a new projectItem for the passed itemType
		/// </summary>
		public override ProjectItem CreateProjectItem(MSBuild.BuildItem item)
		{
			switch (item.Name) {
				case "Reference":
					return new ReferenceProjectItem(this, item);
				case "ProjectReference":
					return new ProjectReferenceProjectItem(this, item);
				case "COMReference":
					return new ComReferenceProjectItem(this, item);
				case "Import":
					return new ImportProjectItem(this, item);
					
				case "None":
				case "Compile":
				case "EmbeddedResource":
				case "Resource":
				case "Content":
				case "Folder":
					return new FileProjectItem(this, item);
					
				case "WebReferenceUrl":
					return new WebReferenceUrl(this, item);
					
				case "WebReferences":
					return new WebReferencesProjectItem(this, item);
					
				default:
					if (this.AvailableFileItemTypes.Contains(new ItemType(item.Name))
					    || SafeFileExists(this.Directory, item.FinalItemSpec))
					{
						return new FileProjectItem(this, item);
					} else {
						return base.CreateProjectItem(item);
					}
			}
		}
コード例 #8
0
		/// <summary>
		/// Get the parent node of an msbuild item
		/// </summary>
		/// <param name="item">msbuild item</param>
		/// <returns>parent node</returns>
		private HierarchyNode GetItemParentNode(MSBuild.BuildItem item)
		{
			HierarchyNode currentParent = this;
			string strPath = item.FinalItemSpec;

			strPath = Path.GetDirectoryName(strPath);
			if(strPath.Length > 0)
			{
				// Use the relative to verify the folders...
				currentParent = this.CreateFolderNodes(strPath);
			}
			return currentParent;
		}
コード例 #9
0
		private string GetOutputPath(MSBuild.BuildPropertyGroup properties)
		{
			this.currentConfig = properties;
			string outputPath = GetProjectProperty("OutputPath");

			if(!String.IsNullOrEmpty(outputPath))
			{
				outputPath = outputPath.Replace('/', Path.DirectorySeparatorChar);
				if(outputPath[outputPath.Length - 1] != Path.DirectorySeparatorChar)
					outputPath += Path.DirectorySeparatorChar;
			}

			return outputPath;
		}
コード例 #10
0
		/// <summary>
		/// Add a dependent file node to the hierarchy
		/// </summary>
		/// <param name="item">msbuild item to add</param>
		/// <param name="parentNode">Parent Node</param>
		/// <returns>Added node</returns>
		private HierarchyNode AddDependentFileNodeToNode(MSBuild.BuildItem item, HierarchyNode parentNode)
		{
			FileNode node = this.CreateDependentFileNode(new ProjectElement(this, item, false));
			parentNode.AddChild(node);

			// Make sure to set the HasNameRelation flag on the dependent node if it is related to the parent by name
			if(!node.HasParentNodeNameRelation && string.Compare(node.GetRelationalName(), parentNode.GetRelationalName(), StringComparison.OrdinalIgnoreCase) == 0)
			{
				node.HasParentNodeNameRelation = true;
			}

			return node;
		}
コード例 #11
0
		/// <summary>
		/// Add a file node to the hierarchy
		/// </summary>
		/// <param name="item">msbuild item to add</param>
		/// <param name="parentNode">Parent Node</param>
		/// <returns>Added node</returns>
		private HierarchyNode AddFileNodeToNode(MSBuild.BuildItem item, HierarchyNode parentNode)
		{
			FileNode node = this.CreateFileNode(new ProjectElement(this, item, false));
			parentNode.AddChild(node);
			return node;
		}
コード例 #12
0
		static void EndXmlManipulation(MSBuild.Project project)
		{
			MarkProjectAsDirtyForReprocessXml(project);
		}
コード例 #13
0
		/// <summary>
		/// Changes the value of the ProjectPath property on an existing import.
		/// Note: this methods causes the project to recreate all imports, so existing import
		/// instances might not be affected.
		/// </summary>
		public static void SetImportProjectPath(MSBuildBasedProject project, MSBuild.Import import,
		                                        string newRawPath)
		{
			if (project == null)
				throw new ArgumentNullException("project");
			if (import == null)
				throw new ArgumentNullException("import");
			if (newRawPath == null)
				throw new ArgumentNullException("newRawPath");
			
			lock (project.SyncRoot) {
				XmlAttribute a = (XmlAttribute)typeof(MSBuild.Import).InvokeMember(
					"ProjectPathAttribute",
					BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
					null, import, null
				);
				a.Value = newRawPath;
				EndXmlManipulation(project.MSBuildProject);
			}
			project.CreateItemsListFromMSBuild();
		}
コード例 #14
0
		/// <summary>
		/// Gets all custom metadata names defined directly on the item, ignoring defaulted metadata entries.
		/// </summary>
		public static IList<string> GetCustomMetadataNames(MSBuild.BuildItem item)
		{
			PropertyInfo prop = typeof(MSBuild.BuildItem).GetProperty("ItemDefinitionLibrary", BindingFlags.Instance | BindingFlags.NonPublic);
			object oldValue = prop.GetValue(item, null);
			prop.SetValue(item, null, null);
			IList<string> result = (IList<string>)item.CustomMetadataNames;
			prop.SetValue(item, oldValue, null);
			return result;
		}
コード例 #15
0
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(MSBuild.Project buildProject)
        {
            foreach (string referenceType in SupportedReferenceTypes)
            {
                MSBuild.BuildItemGroup refererncesGroup = buildProject.GetEvaluatedItemsByName(referenceType);

                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                // If the project was loaded for browsing we should still create the nodes but as not resolved.
                if (this.ProjectMgr.HasPassedSecurityChecks && isAssemblyReference && this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences) != MSBuildResult.Successful)
                {
                    continue;
                }

                foreach (MSBuild.BuildItem item in refererncesGroup)
                {
                    ProjectElement element = new ProjectElement(this.ProjectMgr, item, false);

                    ReferenceNode node = CreateReferenceNode(referenceType, element);

                    if (node != null)
                    {
                        // Make sure that we do not want to add the item twice to the ui hierarchy
                        // We are using here the UI representation of the Node namely the Caption to find that out, in order to
                        // avoid different representation problems.
                        // Example :<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                        //		  <Reference Include="EnvDTE80" />
                        bool found = false;
                        for (HierarchyNode n = this.FirstChild; n != null && !found; n = n.NextSibling)
                        {
                            if (String.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                            }
                        }

                        if (!found)
                        {
                            this.AddChild(node);
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: Project.cs プロジェクト: hesam/SketchSharp
        /// <include file='doc\Project.uex' path='docs/doc[@for="Project.GetBoolAttr"]/*' />
        private bool GetBoolAttr(MSBuild.PropertyGroup properties, string name)
        {
            this.currentConfig = properties;
            string s = GetProjectProperty(name);

            return (s != null && s.ToLower().Trim() == "true");
        }
コード例 #17
0
ファイル: Project.cs プロジェクト: hesam/SketchSharp
        /// <include file='doc\Project.uex' path='docs/doc[@for="Project.GetAssemblyName"]/*' />
        private string GetAssemblyName(MSBuild.PropertyGroup properties)
        {
            this.currentConfig = properties;
            string name = null;

            name = GetProjectProperty("AssemblyName");
            if (name == null)
                name = this.Caption;

            string outputtype = GetProjectProperty("OutputType", false);

            if (outputtype == "library")
            {
                outputtype = outputtype.ToLower();
                name += ".dll";
            }
            else
            {
                name += ".exe";
            }

            return name;
        }
コード例 #18
0
ファイル: Project.cs プロジェクト: hesam/SketchSharp
        /// <summary>
        /// Constructor to Wrap an existing MSBuild.Item
        /// Only have internal constructors as the only one who should be creating
        /// such object is the project itself (see Project.CreateFileNode()).
        /// </summary>
        /// <param name="project">Project that owns this item</param>
        /// <param name="existingItem">an MSBuild.Item; can be null if virtualFolder is true</param>
        /// <param name="virtualFolder">Is this item virtual (such as reference folder)</param>
        internal ProjectElement(Project project, MSBuild.Item existingItem, bool virtualFolder)
        {
            if (project == null)
                throw new ArgumentNullException("project", String.Format(SR.GetString(SR.AddToNullProjectError), existingItem.Include));
            if (!virtualFolder && existingItem == null)
                throw new ArgumentNullException("existingItem");

            // Keep a reference to project and item
            itemProject = project;
            item = existingItem;
            isVirtual = virtualFolder;
        }
コード例 #19
0
ファイル: Project.cs プロジェクト: hesam/SketchSharp
        /// <summary>
        /// For internal use only.
        /// This creates a copy of an existing configuration and add it to the project.
        /// Caller should change the condition on the PropertyGroup.
        /// If derived class want to accomplish this, they should call ConfigProvider.AddCfgsOfCfgName()
        /// It is expected that in the future MSBuild will have support for this so we don't have to
        /// do it manually.
        /// </summary>
        /// <param name="group">PropertyGroup to clone</param>
        /// <returns></returns>
        internal MSBuild.PropertyGroup ClonePropertyGroup(MSBuild.PropertyGroup group)
        {
            // Create a new (empty) PropertyGroup
            MSBuild.PropertyGroup newPropertyGroup = this.projFile.AddNewPropertyGroup(true);

            // Now copy everything from the group we are trying to clone to the group we are creating
            if (group.Condition != "")
                newPropertyGroup.Condition = group.Condition;
            foreach (MSBuild.Property prop in group)
            {
                MSBuild.Property newProperty = newPropertyGroup.AddNewProperty(prop.Name, prop.Value);
                if (prop.Condition != "")
                    newProperty.Condition = prop.Condition;
            }

            return newPropertyGroup;
        }
コード例 #20
0
		internal static void MarkProjectAsDirtyForReprocessXml(MSBuild.Project project)
		{
			typeof(MSBuild.Project).InvokeMember(
				"MarkProjectAsDirtyForReprocessXml",
				BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
				null, project, null
			);
		}
コード例 #21
0
		private bool GetBoolAttr(MSBuild.BuildPropertyGroup properties, string name)
		{
			this.currentConfig = properties;
			string s = GetProjectProperty(name);

			return (s != null && s.ToUpperInvariant().Trim() == "TRUE");
		}
コード例 #22
0
		/// <summary>
		/// Finds the <c>BuildProperty</c> object used to store <paramref name="propertyName"/>
		/// in the specified configuration/platform.
		/// </summary>
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The property to look for.</param>
		/// <param name="group">[Out], the property group in which the property was found</param>
		/// <param name="location">[Out], the storage location the condition of the property
		/// group was referring to</param>
		protected MSBuild.BuildProperty FindPropertyObject(string configuration, string platform,
		                                                   string propertyName,
		                                                   out MSBuild.BuildPropertyGroup group,
		                                                   out PropertyStorageLocations location)
		{
			if (string.IsNullOrEmpty(configuration)) configuration = ActiveConfiguration;
			if (string.IsNullOrEmpty(platform))      platform = ActivePlatform;
			
			// We need to use ToArray because EvaluateMSBuildCondition invalidates the list
			// of property groups.
			foreach (MSBuild.BuildPropertyGroup g
			         in Linq.ToList(Linq.CastTo<MSBuild.BuildPropertyGroup>(project.PropertyGroups)))
			{
				if (g.IsImported) {
					continue;
				}
				MSBuild.BuildProperty property = MSBuildInternals.GetProperty(g, propertyName);
				if (property == null)
					continue;
				if (EvaluateMSBuildCondition(configuration, platform, g.Condition)) {
					location = MSBuildInternals.GetLocationFromCondition(g.Condition);
					group = g;
					return property;
				}
			}
			location = PropertyStorageLocations.Unknown;
			group = null;
			return null;
		}
コード例 #23
0
		private string GetAssemblyName(MSBuild.BuildPropertyGroup properties)
		{
			this.currentConfig = properties;
			string name = null;

			name = GetProjectProperty(ProjectFileConstants.AssemblyName);
			if(name == null)
				name = this.Caption;

			string outputtype = GetProjectProperty(ProjectFileConstants.OutputType, false);

			if(outputtype == "library")
			{
				outputtype = outputtype.ToLowerInvariant();
				name += ".dll";
			}
			else
			{
				name += ".exe";
			}

			return name;
		}
コード例 #24
0
		internal static void InitializeMSBuildProject(MSBuild.Project project)
		{
			project.GlobalProperties.SetProperty("BuildingInsideVisualStudio", "true");
			foreach (KeyValuePair<string, string> pair in MSBuildEngine.MSBuildProperties) {
				project.GlobalProperties.SetProperty(pair.Key, pair.Value, true);
			}
		}
コード例 #25
0
		/// <summary>
		/// copy properties from g into a new property group for newConfiguration and newPlatform
		/// </summary>
		void CopyProperties(MSBuild.BuildPropertyGroup g, string newConfiguration, string newPlatform)
		{
			MSBuild.BuildPropertyGroup ng = project.AddNewPropertyGroup(false);
			ng.Condition = CreateCondition(newConfiguration, newPlatform);
			foreach (MSBuild.BuildProperty p in g) {
				ng.AddNewProperty(p.Name, p.Value);
			}
		}
コード例 #26
0
		static XmlElement BeginXmlManipulation(MSBuild.Project project)
		{
			return (XmlElement)typeof(MSBuild.Project).InvokeMember(
				"ProjectElement",
				BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
				null, project, null
			);
		}
コード例 #27
0
		/// <summary>
		/// For internal use only.
		/// This creates a copy of an existing configuration and add it to the project.
		/// Caller should change the condition on the PropertyGroup.
		/// If derived class want to accomplish this, they should call ConfigProvider.AddCfgsOfCfgName()
		/// It is expected that in the future MSBuild will have support for this so we don't have to
		/// do it manually.
		/// </summary>
		/// <param name="group">PropertyGroup to clone</param>
		/// <returns></returns>
		internal MSBuild.BuildPropertyGroup ClonePropertyGroup(MSBuild.BuildPropertyGroup group)
		{
			// Create a new (empty) PropertyGroup
			MSBuild.BuildPropertyGroup newPropertyGroup = this.buildProject.AddNewPropertyGroup(false);

			// Now copy everything from the group we are trying to clone to the group we are creating
			if(!String.IsNullOrEmpty(group.Condition))
				newPropertyGroup.Condition = group.Condition;
			foreach(MSBuild.BuildProperty prop in group)
			{
				MSBuild.BuildProperty newProperty = newPropertyGroup.AddNewProperty(prop.Name, prop.Value);
				if(!String.IsNullOrEmpty(prop.Condition))
					newProperty.Condition = prop.Condition;
			}

			return newPropertyGroup;
		}
コード例 #28
0
		/// <summary>
		/// Add an item to the hierarchy based on the item path
		/// </summary>
		/// <param name="item">Item to add</param>
		/// <returns>Added node</returns>
		private HierarchyNode AddIndependentFileNode(MSBuild.BuildItem item)
		{
			HierarchyNode currentParent = GetItemParentNode(item);
			return AddFileNodeToNode(item, currentParent);
		}
コード例 #29
0
		/// <summary>
		/// This method returns new project element based on existing MSBuild item. It does not modify/add project/build hierarchy at all.
		/// </summary>
		/// <param name="item">MSBuild item instance</param>
		/// <returns>wrapping project element</returns>
		public ProjectElement GetProjectElement(MSBuild.BuildItem item)
		{
			return new ProjectElement(this, item, false);
		}
コード例 #30
0
		/// <summary>
		/// Removes all &lt;Import&gt; nodes from a project.
		/// </summary>
		public static void ClearImports(MSBuild.Project project)
		{
			if (project == null)
				throw new ArgumentNullException("project");
			
			XmlElement xmlProject = BeginXmlManipulation(project);
			List<XmlNode> nodesToRemove = new List<XmlNode>();
			foreach (XmlNode node in xmlProject.ChildNodes) {
				if (node.NodeType == XmlNodeType.Element && node.Name == "Import") {
					nodesToRemove.Add(node);
				}
			}
			foreach (XmlNode node in nodesToRemove) {
				xmlProject.RemoveChild(node);
			}
			EndXmlManipulation(project);
		}