本文整理汇总了C#中Microsoft.Build.Construction.XmlElementWithLocation.RemoveAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElementWithLocation.RemoveAttribute方法的具体用法?C# XmlElementWithLocation.RemoveAttribute怎么用?C# XmlElementWithLocation.RemoveAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Construction.XmlElementWithLocation
的用法示例。
在下文中一共展示了XmlElementWithLocation.RemoveAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: if
/// <summary>
/// Processes the <Folder> element, and adds an appropriate item to the
/// filesItemGroup.
/// </summary>
/// <owner>RGoel</owner>
private void ProcessFolderElement
(
XmlElementWithLocation folderElement,
ProjectItemGroupElement filesItemGroup
)
{
// Make sure this is the <Folder> element.
error.VerifyThrow((folderElement != null) &&
(folderElement.Name == VSProjectElements.folder),
"Expected <Folder> element.");
// Make sure the caller has already created an ProjectItemGroupElement for us to
// put the new items in.
error.VerifyThrow(filesItemGroup != null, "Received null ProjectItemGroupElement");
// Get the required "RelPath" attribute.
string relPath = folderElement.GetAttribute(VSProjectAttributes.relPath);
ProjectErrorUtilities.VerifyThrowInvalidProject((relPath != null) && (relPath.Length > 0),
folderElement.Location, "MissingAttribute", VSProjectAttributes.relPath, VSProjectElements.folder);
// Remove the "RelPath" attribute, so we don't end up adding it twice.
folderElement.RemoveAttribute(VSProjectAttributes.relPath);
// We need to find out what type of folder this is -- a web references
// folder, a web reference URL, or just an empty project folder.
// See if there's a "WebReferences" attribute on the <Folder> element. If so,
// and the value is set to "True", then it's a web reference folder.
string webReferences = folderElement.GetAttribute(VSProjectAttributes.webReferences);
// Remove the "WebReferences" attribute, so we don't end up adding it twice.
folderElement.RemoveAttribute(VSProjectAttributes.webReferences);
// See if there's a "WebReferenceURL" attribute. If so, it's a web reference
// URL.
string webReferenceUrl = folderElement.GetAttribute(VSProjectAttributes.webReferenceUrl);
// Remove the "WebReferenceURL" attribute, so we don't end up adding it twice.
folderElement.RemoveAttribute(VSProjectAttributes.webReferenceUrl);
ProjectItemElement newFolderItem;
if ((webReferences != null) && (0 == String.Compare(webReferences, "true", StringComparison.OrdinalIgnoreCase)))
{
// This is a web reference folder.
// The <Folder> element gets converted to XMake as an item of type
// "WebReferences". The "Include" will contain the relative path.
// For example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <Folder
// RelPath = "Web References\"
// WebReferences = "TRUE"
// />
// -----------------------------------------------------------------------
// XMake format:
// =============
// <WebReferences Include = "Web References\" />
// -----------------------------------------------------------------------
newFolderItem = filesItemGroup.AddItem(XMakeProjectStrings.webReferences,
ProjectCollection.Escape(relPath));
}
else if ((webReferenceUrl != null) && (webReferenceUrl.Length > 0))
{
// This is an actual web reference URL.
// The <Folder> element gets converted to XMake as an item of type
// "WebReferenceURL". The "Include" will contain the URL.
// For example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <Folder
// RelPath = "Web References\mobileakipman\"
// WebReferenceUrl = "http://mobileakipman/HelloName/service1.asmx"
// UrlBehavior = "Static"
// />
// -----------------------------------------------------------------------
// XMake format:
// =============
// <WebReferenceUrl Include="http://mobileakipman/HelloName/service1.asmx">
// <RelPath>Web References\mobileakipman\</RelPath>
// <UrlBehavior>Static</UrlBehavior>
// </WebReferenceUrl>
// -----------------------------------------------------------------------
newFolderItem = filesItemGroup.AddItem(XMakeProjectStrings.webReferenceUrl,
ProjectCollection.Escape(webReferenceUrl));
newFolderItem.AddMetadata(XMakeProjectStrings.relPath, ProjectCollection.Escape(relPath));
// Whidbey projects have some new properties to control the behavior of the
// proxy generation. For projects migrated from Everett, we want to force
// the proxy generation to mimic the Everett behavior, so that people's projects
// still work the same as they did in Everett. (These properties did not
// exist in Everett.) See spec at:
// http://devdiv/SpecTool/Documents/Whidbey/VSCore/Solution%20Project%20Build/FeatureSpecs/Project-WebReferences.doc
if (!this.newWebReferencePropertiesAdded)
//.........这里部分代码省略.........
示例3: foreach
/// <summary>
/// Processes the <Service> element, and add an appropriate reference
/// items to the startupServicesItemGroup.
/// </summary>
/// <owner>RGoel</owner>
private void ProcessServiceElement
(
XmlElementWithLocation serviceElement,
ProjectItemGroupElement startupServicesItemGroup
)
{
// Make sure this is the <Service> element.
error.VerifyThrow((serviceElement != null) &&
(serviceElement.Name == VSProjectElements.service),
"Expected <Service> element.");
// Make sure the caller has already created an ProjectItemGroupElement for us to
// put the new items in.
error.VerifyThrow(startupServicesItemGroup != null, "Received null ProjectItemGroupElement");
// Get the required "ID" attribute.
string id = serviceElement.GetAttribute(VSProjectAttributes.id);
ProjectErrorUtilities.VerifyThrowInvalidProject((id != null) && (id.Length > 0), serviceElement.Location,
"MissingAttribute", VSProjectAttributes.id, VSProjectElements.service);
// Remove the "ID" attribute, so it doesn't show up in our loop later.
serviceElement.RemoveAttribute(VSProjectAttributes.id);
// The <Service> element gets converted to XMake as an item of type "Service".
// The "ID" attribute becomes the "Include" for the new item. For
// example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <Service ID = "ABCD1234-78F4-4F98-AFD6-720DA6E648A2" />
// -----------------------------------------------------------------------
// XMake format:
// =============
// <Service Include="ABCD1234-78F4-4F98-AFD6-720DA6E648A2" />
// -----------------------------------------------------------------------
startupServicesItemGroup.AddItem(XMakeProjectStrings.service, ProjectCollection.Escape(id));
// There should be no other attributes on the <Service> element (besides
// "ID" which we already took care of). But loop through them
// anyway, so we can emit a useful error message.
foreach (XmlAttributeWithLocation serviceAttribute in serviceElement.Attributes)
{
ProjectErrorUtilities.VerifyThrowInvalidProject(false, serviceAttribute.Location, "UnrecognizedAttribute",
serviceAttribute.Name, VSProjectElements.service);
}
// There should be no children of the <Service> element.
ProjectXmlUtilities.VerifyThrowProjectNoChildElements(serviceElement);
}
示例4: IsFilePresentButEmpty
/// <summary>
/// Processes the <File> element, and adds an appropriate item to the
/// filesItemGroup.
/// </summary>
/// <owner>RGoel</owner>
private void ProcessFileElement
(
XmlElementWithLocation fileElement,
ProjectItemGroupElement filesItemGroup
)
{
// Make sure this is the <File> element.
error.VerifyThrow((fileElement != null) &&
(fileElement.Name == VSProjectElements.file),
"Expected <File> element.");
// Make sure the caller has already created an ProjectItemGroupElement for us to
// put the new items in.
error.VerifyThrow(filesItemGroup != null, "Received null ProjectItemGroupElement");
// Get the required "RelPath" attribute.
string relPath = fileElement.GetAttribute(VSProjectAttributes.relPath);
ProjectErrorUtilities.VerifyThrowInvalidProject((relPath != null) && (relPath.Length > 0),
fileElement.Location, "MissingAttribute", VSProjectAttributes.relPath, VSProjectElements.file);
// Remove the "RelPath" attribute, so we don't end up adding it twice.
fileElement.RemoveAttribute(VSProjectAttributes.relPath);
// Get the "Link" attribute. This is for linked items only.
string linkPath = fileElement.GetAttribute(VSProjectAttributes.link);
// Remove the "Link" attribute, so we don't end up adding it twice.
fileElement.RemoveAttribute(VSProjectAttributes.link);
// Get the "BuildAction" attribute. If it doesn't exist, figure out
// what the build action is based on the file extension. This is
// what the project loading code does in VS.
string buildAction = fileElement.GetAttribute(VSProjectAttributes.buildAction);
if ((buildAction == null) || (buildAction.Length == 0))
{
buildAction = VSProjectAttributes.buildActionNone;
}
// Remove the "BuildAction" attribute, so we don't end up adding it twice.
fileElement.RemoveAttribute(VSProjectAttributes.buildAction);
ProjectItemElement newFileItem;
// Bug Whidbey #248965. If a .resx file is completely empty, do not include a reference
// to it in the upgraded project file.
if (!
(0 == String.Compare(Path.GetExtension(relPath), ".resx", StringComparison.OrdinalIgnoreCase)
&& IsFilePresentButEmpty(relPath, linkPath))
)
{
// Add the new item to XMake.
if ((linkPath == null) || (linkPath.Length == 0))
{
// Normal item.
// The <File> element gets converted to XMake as a new item, where
// the item type is the BuildAction, and the "Include" contains
// the relative path to the item. For
// example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <File
// RelPath = "Properties\PropertyGroupCollection.cs"
// SubType = "Code"
// BuildAction = "Compile"
// />
// -----------------------------------------------------------------------
// XMake format:
// =============
// <Compile Include = "Properties\PropertyGroupCollection.cs">
// <SubType>Code</SubType>
// </Compile>
// -----------------------------------------------------------------------
newFileItem = filesItemGroup.AddItem(buildAction, ProjectCollection.Escape(relPath));
}
else
{
// Linked item.
// The <File> element gets converted to XMake as a new item, where
// the item type is the BuildAction, the "Include" contains
// the physical relative path to the item, and the non-XMake "Link"
// attribute contains the project-relative path for item (for display
// purposes in the Solution Explorer). For example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <File
// RelPath = "Properties\PropertyGroupCollection.cs"
// Link = "c:\Rajeev\External\PropertyGroupCollection.cs"
// SubType = "Code"
// BuildAction = "Compile"
// />
// -----------------------------------------------------------------------
// XMake format:
// =============
//.........这里部分代码省略.........
示例5: ConvertAssemblyReference
/// <summary>
/// Given an element corresponding to a .NET Assembly reference, create the appropriate element in the new project
/// </summary>
/// <param name="referenceElement"></param>
/// <param name="referencesItemGroup"></param>
/// <param name="referenceName"></param>
/// <returns></returns>
private ProjectItemElement ConvertAssemblyReference(XmlElementWithLocation referenceElement, ProjectItemGroupElement referencesItemGroup, string referenceName)
{
ProjectItemElement newReferenceItem;
// This is a regular .NET assembly reference.
// This gets added as a new XMake item of type "Reference". The "Include"
// attribute is the assembly name, and all the other attributes remain
// the same. For example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <Reference
// Name = "System.Xml"
// AssemblyName = "System.Xml"
// HintPath = "..\..\binaries\x86chk\bin\i386\System.Xml.dll"
// />
// -----------------------------------------------------------------------
// XMake format:
// =============
// <Reference Include="System.Xml">
// <Name>System.Xml</Name>
// <HintPath>..\..\binaries\x86chk\bin\i386\System.Xml.dll</HintPath>
// </Reference>
// -----------------------------------------------------------------------
// Get the "AssemblyName" attribute. If not found, just use the value from the
// "Name" attribute. This is what the project loading code does in VS.
string assemblyName = referenceElement.GetAttribute(VSProjectAttributes.assemblyName);
if ((assemblyName == null) || (assemblyName.Length == 0))
{
assemblyName = referenceName;
}
else
{
// Remove the "AssemblyName" attribute so we don't add it again at
// the end.
referenceElement.RemoveAttribute(VSProjectAttributes.assemblyName);
}
// MyType should only be added when System.Windows.Forms is present. If this
// reference is seen, then set a flag so we can later add MyType.
if (0 == String.Compare("System.Windows.Forms", assemblyName, StringComparison.OrdinalIgnoreCase))
{
hasWindowsFormsReference = true;
}
// Remove hint paths that we think are to RTM or Everett framework assemblies
string hintPath = referenceElement.GetAttribute(VSProjectAttributes.hintPath);
if (hintPath != null)
{
hintPath = hintPath.ToUpper(CultureInfo.InvariantCulture);
if (hintPath.IndexOf(LegacyFrameworkPaths.RTMFrameworkPath, StringComparison.Ordinal) != -1 ||
hintPath.IndexOf(LegacyFrameworkPaths.EverettFrameworkPath, StringComparison.Ordinal) != -1 ||
hintPath.IndexOf(LegacyFrameworkPaths.JSharpRTMFrameworkPath, StringComparison.Ordinal) != -1)
{
referenceElement.RemoveAttribute(VSProjectAttributes.hintPath);
}
}
newReferenceItem = referencesItemGroup.AddItem(XMakeProjectStrings.reference, ProjectCollection.Escape(assemblyName));
return newReferenceItem;
}
示例6: ConvertClassicComReference
/// <summary>
/// Given an element corresponding to a COM reference, create the appropriate element in the new project
/// </summary>
/// <param name="referenceElement"></param>
/// <param name="referencesItemGroup"></param>
/// <param name="referenceName"></param>
/// <returns></returns>
private static ProjectItemElement ConvertClassicComReference(XmlElementWithLocation referenceElement, ProjectItemGroupElement referencesItemGroup, string referenceName)
{
ProjectItemElement newReferenceItem;
// This is a classic COM reference.
// This gets added as a new XMake item of type "COMReference".
// The "Include" attribute will contain the reference name,
// and all the other attributes remain the same. For example,
// -----------------------------------------------------------------------
// Everett format:
// ===============
// <Reference
// Name = "UTILITIESLib"
// Guid = "{0EF79DA1-6555-11D2-A889-00AA006C2A9A}"
// VersionMajor = "1"
// VersionMinor = "0"
// Lcid = "0"
// WrapperTool = "tlbimp"
// />
// -----------------------------------------------------------------------
// XMake format:
// =============
// <COMReference Include = "UTILITIESLib">
// <Guid>{0EF79DA1-6555-11D2-A889-00AA006C2A9A}</Guid>
// <VersionMajor>1</VersionMajor>
// <VersionMinor>0</VersionMinor>
// <Lcid>0</Lcid>
// <WrapperTool>tlbimp</WrapperTool>
// </COMReference>
// -----------------------------------------------------------------------
// Remove the "Name" attribute so we don't add it again at the end.
referenceElement.RemoveAttribute(VSProjectAttributes.name);
// Add a new item to XMake of type "COMReference".
newReferenceItem = referencesItemGroup.AddItem(XMakeProjectStrings.comReference, ProjectCollection.Escape(referenceName));
return newReferenceItem;
}