当前位置: 首页>>代码示例>>C#>>正文


C# XmlElementWithLocation.SetAttribute方法代码示例

本文整理汇总了C#中Microsoft.Build.Construction.XmlElementWithLocation.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElementWithLocation.SetAttribute方法的具体用法?C# XmlElementWithLocation.SetAttribute怎么用?C# XmlElementWithLocation.SetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.Construction.XmlElementWithLocation的用法示例。


在下文中一共展示了XmlElementWithLocation.SetAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetOrRemoveAttribute

 /// <summary>
 /// Sets the value of an attribute, removing the attribute if the value is null, but still setting it 
 /// if the value is the empty string. Returns the attribute, or null if it was removed.
 /// UNDONE: Make this return a bool if the attribute did not change, so we can avoid dirtying.
 /// </summary>
 internal static XmlAttributeWithLocation SetOrRemoveAttribute(XmlElementWithLocation element, string name, string value, bool allowSettingEmptyAttributes)
 {
     if (value == null || (!allowSettingEmptyAttributes && value.Length == 0))
     {
         // The caller passed in a null or an empty value.  So remove the attribute.
         element.RemoveAttribute(name);
         return null;
     }
     else
     {
         // Set the new attribute value
         element.SetAttribute(name, value);
         XmlAttributeWithLocation attribute = (XmlAttributeWithLocation)element.Attributes[name];
         return attribute;
     }
 }
开发者ID:cdmihai,项目名称:msbuild,代码行数:21,代码来源:ProjectXmlUtilities.cs

示例2: ConvertProjectToProjectReference

        /// <summary>
        /// Given an element corresponding to a P2P reference, create the appropriate element in the new project
        /// </summary>
        /// <param name="referenceElement"></param>
        /// <param name="referencesItemGroup"></param>
        /// <param name="referenceName"></param>
        /// <param name="referencedProjectGuid"></param>
        /// <returns></returns>
        private ProjectItemElement ConvertProjectToProjectReference(XmlElementWithLocation referenceElement, ProjectItemGroupElement referencesItemGroup, string referenceName, ref string referencedProjectGuid)
        {
            ProjectItemElement newReferenceItem;
            // This is a project-to-project reference.

            // This gets added as a new XMake item of type "ProjectReference".
            // The "Include" attribute should be the relative path from the
            // current project to the referenced project file.  For example,
            // -----------------------------------------------------------------------
            // Everett format:
            // ===============
            //    <Reference
            //        Name = "XMakeTasks"
            //        Project = "{44342961-78F4-4F98-AFD6-720DA6E648A2}"
            //        Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
            //    />
            // -----------------------------------------------------------------------
            // XMake format:
            // =============
            //    <ProjectReference Include = "..\XMakeTasks\XMakeTasks.csproj">
            //          <Name>XMakeTasks</Name>
            //          <Project>{44342961-78F4-4F98-AFD6-720DA6E648A2}</Project>
            //          <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
            //    </ProjectReference>
            // -----------------------------------------------------------------------

            // Apparently, sometimes project reference guids contain additional goo with relative project path.
            // Just strip it off. The project system does the same thing, and by doing this early we make
            // sure that we have the correct guid attribute in the project file and ResolveNonMSBuildReferences
            // does not complain about invalid characters there which causes all the references to fail to resolve.
            int barIndex = referencedProjectGuid.IndexOf('|');
            if (barIndex != -1)
            {
                referencedProjectGuid = referencedProjectGuid.Remove(barIndex);
                referenceElement.SetAttribute(VSProjectAttributes.project, referencedProjectGuid);
            }

            string pathToReferencedProject = this.GetRelativePathToReferencedProject(referencedProjectGuid);

            if (pathToReferencedProject != null)
            {
                // For VSD Projects, we want to transform all Everett ( .csdproj & .vbdproj ) project 2 project references into
                // Whidbey ( .csproj & .vbproj ) references.
                if (0 == String.Compare(Path.GetExtension(pathToReferencedProject),
                                        XMakeProjectStrings.csdprojFileExtension,
                                        StringComparison.OrdinalIgnoreCase))
                {
                    pathToReferencedProject = Path.ChangeExtension(pathToReferencedProject, XMakeProjectStrings.csprojFileExtension);
                }
                else if (0 == String.Compare(Path.GetExtension(pathToReferencedProject),
                                             XMakeProjectStrings.vbdprojFileExtension,
                                             StringComparison.OrdinalIgnoreCase))
                {
                    pathToReferencedProject = Path.ChangeExtension(pathToReferencedProject, XMakeProjectStrings.vbprojFileExtension);
                }
            }

            // Add a new item to XMake of type "ProjectReference".  If we were able to find
            // the relative path to the project, use it for the "Include", otherwise just use
            // the project name.
            string value = (pathToReferencedProject != null) ? pathToReferencedProject : referenceName;
            newReferenceItem = referencesItemGroup.AddItem(XMakeProjectStrings.projectReference, ProjectCollection.Escape(value));
            return newReferenceItem;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:72,代码来源:ProjectFileConverter.cs


注:本文中的Microsoft.Build.Construction.XmlElementWithLocation.SetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。