private void AddReferencesToCommandLine(CommandLineBuilderExtension commandLine) { if (base.References == null || base.References.Length == 0) { return; } ITaskItem[] references = base.References; for (int i = 0; i < references.Length; i++) { ITaskItem taskItem = references[i]; string metadata = taskItem.GetMetadata("Aliases"); string switchName = "/reference:"; bool flag = MetadataConversionUtilities.TryConvertItemMetadataToBool(taskItem, "EmbedInteropTypes"); if (flag) { switchName = "/link:"; } if (metadata == null || metadata.Length == 0) { commandLine.AppendSwitchIfNotNull(switchName, taskItem.ItemSpec); } else { string[] array = metadata.Split(new char[] { ',' }); string[] array2 = array; for (int j = 0; j < array2.Length; j++) { string text = array2[j]; string text2 = text.Trim(); if (text.Length != 0) { if (text2.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1) { ErrorUtilities.VerifyThrowArgument(false, "Csc.AssemblyAliasContainsIllegalCharacters", taskItem.ItemSpec, text2); } if (string.Compare("global", text2, StringComparison.OrdinalIgnoreCase) == 0) { commandLine.AppendSwitchIfNotNull(switchName, taskItem.ItemSpec); } else { commandLine.AppendSwitchAliased(switchName, text2, taskItem.ItemSpec); } } } } } }
private void AddReferencesToCommandLine(CommandLineBuilderExtension commandLine) { if ((base.References != null) && (base.References.Length != 0)) { foreach (ITaskItem item in base.References) { string metadata = item.GetMetadata("Aliases"); string switchName = "/reference:"; if (MetadataConversionUtilities.TryConvertItemMetadataToBool(item, "EmbedInteropTypes")) { switchName = "/link:"; } if ((metadata == null) || (metadata.Length == 0)) { commandLine.AppendSwitchIfNotNull(switchName, item.ItemSpec); } else { foreach (string str3 in metadata.Split(new char[] { ',' })) { string str4 = str3.Trim(); if (str3.Length != 0) { if (str4.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1) { Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgument(false, "Csc.AssemblyAliasContainsIllegalCharacters", item.ItemSpec, str4); } if (string.Compare("global", str4, StringComparison.OrdinalIgnoreCase) == 0) { commandLine.AppendSwitchIfNotNull(switchName, item.ItemSpec); } else { commandLine.AppendSwitchAliased(switchName, str4, item.ItemSpec); } } } } } } }
private void AddReferencesToCommandLine(CommandLineBuilderExtension commandLine) { if ((base.References != null) && (base.References.Length != 0)) { foreach (ITaskItem item in base.References) { string metadata = item.GetMetadata("Aliases"); string switchName = "/reference:"; if (MetadataConversionUtilities.TryConvertItemMetadataToBool(item, "EmbedInteropTypes")) { switchName = "/link:"; } if ((metadata == null) || (metadata.Length == 0)) { commandLine.AppendSwitchIfNotNull(switchName, item.ItemSpec); } else { foreach (string str3 in metadata.Split(new char[] { ',' })) { string str4 = str3.Trim(); if (str3.Length != 0) { if (str4.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1) { Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgument(false, "Csc.AssemblyAliasContainsIllegalCharacters", item.ItemSpec, str4); } if (string.Compare("global", str4, StringComparison.OrdinalIgnoreCase) == 0) { commandLine.AppendSwitchIfNotNull(switchName, item.ItemSpec); } else { commandLine.AppendSwitchAliased(switchName, str4, item.ItemSpec); } } } } } } }
/// <summary> /// The C# compiler (starting with Whidbey) supports assembly aliasing for references. /// See spec at http://devdiv/spectool/Documents/Whidbey/VCSharp/Design%20Time/M3%20DCRs/DCR%20Assembly%20aliases.doc. /// This method handles the necessary work of looking at the "Aliases" attribute on /// the incoming "References" items, and making sure to generate the correct /// command-line on csc.exe. The syntax for aliasing a reference is: /// csc.exe /reference:Foo=System.Xml.dll /// /// The "Aliases" attribute on the "References" items is actually a comma-separated /// list of aliases, and if any of the aliases specified is the string "global", /// then we add that reference to the command-line without an alias. /// </summary> /// <param name="commandLine"></param> private void AddReferencesToCommandLine ( CommandLineBuilderExtension commandLine ) { // If there were no references passed in, don't add any /reference: switches // on the command-line. if ((this.References == null) || (this.References.Length == 0)) { return; } // Loop through all the references passed in. We'll be adding separate // /reference: switches for each reference, and in some cases even multiple // /reference: switches per reference. foreach (ITaskItem reference in this.References) { // See if there was an "Alias" attribute on the reference. string aliasString = reference.GetMetadata(ItemMetadataNames.aliases); string switchName = "/reference:"; bool embed = MetadataConversionUtilities.TryConvertItemMetadataToBool ( reference, ItemMetadataNames.embedInteropTypes ); if (embed == true) { switchName = "/link:"; } if ((aliasString == null) || (aliasString.Length == 0)) { // If there was no "Alias" attribute, just add this as a global reference. commandLine.AppendSwitchIfNotNull(switchName, reference.ItemSpec); } else { // If there was an "Alias" attribute, it contains a comma-separated list // of aliases to use for this reference. For each one of those aliases, // we're going to add a separate /reference: switch to the csc.exe // command-line string[] aliases = aliasString.Split(','); foreach (string alias in aliases) { // Trim whitespace. string trimmedAlias = alias.Trim(); if (alias.Length == 0) { continue; } // The alias should be a valid C# identifier. Therefore it cannot // contain comma, space, semicolon, or double-quote. Let's check for // the existence of those characters right here, and bail immediately // if any are present. There are a whole bunch of other characters // that are not allowed in a C# identifier, but we'll just let csc.exe // error out on those. The ones we're checking for here are the ones // that could seriously interfere with the command-line parsing or could // allow parameter injection. if (trimmedAlias.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1) { ErrorUtilities.VerifyThrowArgument ( false, "Csc.AssemblyAliasContainsIllegalCharacters", reference.ItemSpec, trimmedAlias ); } // The alias called "global" is special. It means that we don't // give it an alias on the command-line. if (String.Compare("global", trimmedAlias, StringComparison.OrdinalIgnoreCase) == 0) { commandLine.AppendSwitchIfNotNull(switchName, reference.ItemSpec); } else { // We have a valid (and explicit) alias for this reference. Add // it to the command-line using the syntax: // /reference:Foo=System.Xml.dll commandLine.AppendSwitchAliased(switchName, trimmedAlias, reference.ItemSpec); } } } } }
/// <summary> /// The C# compiler (starting with Whidbey) supports assembly aliasing for references. /// See spec at http://devdiv/spectool/Documents/Whidbey/VCSharp/Design%20Time/M3%20DCRs/DCR%20Assembly%20aliases.doc. /// This method handles the necessary work of looking at the "Aliases" attribute on /// the incoming "References" items, and making sure to generate the correct /// command-line on csc.exe. The syntax for aliasing a reference is: /// csc.exe /reference:Foo=System.Xml.dll /// /// The "Aliases" attribute on the "References" items is actually a comma-separated /// list of aliases, and if any of the aliases specified is the string "global", /// then we add that reference to the command-line without an alias. /// </summary> /// <param name="commandLine"></param> private void AddReferencesToCommandLine ( CommandLineBuilderExtension commandLine ) { // If there were no references passed in, don't add any /reference: switches // on the command-line. if ((this.References == null) || (this.References.Length == 0)) { return; } // Loop through all the references passed in. We'll be adding separate // /reference: switches for each reference, and in some cases even multiple // /reference: switches per reference. foreach (ITaskItem reference in this.References) { // See if there was an "Alias" attribute on the reference. string aliasString = reference.GetMetadata(ItemMetadataNames.aliases); string switchName = "/reference:"; bool embed = MetadataConversionUtilities.TryConvertItemMetadataToBool ( reference, ItemMetadataNames.embedInteropTypes ); if (embed == true) { switchName = "/link:"; } if ((aliasString == null) || (aliasString.Length == 0)) { // If there was no "Alias" attribute, just add this as a global reference. commandLine.AppendSwitchIfNotNull(switchName, reference.ItemSpec); } else { // If there was an "Alias" attribute, it contains a comma-separated list // of aliases to use for this reference. For each one of those aliases, // we're going to add a separate /reference: switch to the csc.exe // command-line string[] aliases = aliasString.Split(','); foreach (string alias in aliases) { // Trim whitespace. string trimmedAlias = alias.Trim(); if (alias.Length == 0) { continue; } // The alias should be a valid C# identifier. Therefore it cannot // contain comma, space, semicolon, or double-quote. Let's check for // the existence of those characters right here, and bail immediately // if any are present. There are a whole bunch of other characters // that are not allowed in a C# identifier, but we'll just let csc.exe // error out on those. The ones we're checking for here are the ones // that could seriously interfere with the command-line parsing or could // allow parameter injection. if (trimmedAlias.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1) { ErrorUtilities.VerifyThrowArgument ( false, "Csc.AssemblyAliasContainsIllegalCharacters", reference.ItemSpec, trimmedAlias ); } // The alias called "global" is special. It means that we don't // give it an alias on the command-line. if (String.Compare("global", trimmedAlias, StringComparison.OrdinalIgnoreCase) == 0) { commandLine.AppendSwitchIfNotNull(switchName, reference.ItemSpec); } else { // We have a valid (and explicit) alias for this reference. Add // it to the command-line using the syntax: // /reference:Foo=System.Xml.dll commandLine.AppendSwitchAliased(switchName, trimmedAlias, reference.ItemSpec); } } } } }
private void AddReferencesToCommandLine(CommandLineBuilderExtension commandLine) { if (base.References == null || base.References.Length == 0) { return; } ITaskItem[] references = base.References; for (int i = 0; i < references.Length; i++) { ITaskItem taskItem = references[i]; string metadata = taskItem.GetMetadata("Aliases"); string switchName = "/reference:"; bool flag = MetadataConversionUtilities.TryConvertItemMetadataToBool(taskItem, "EmbedInteropTypes"); if (flag) { switchName = "/link:"; } if (metadata == null || metadata.Length == 0) { commandLine.AppendSwitchIfNotNull(switchName, taskItem.ItemSpec); } else { string[] array = metadata.Split(new char[] { ',' }); string[] array2 = array; for (int j = 0; j < array2.Length; j++) { string text = array2[j]; string text2 = text.Trim(); if (text.Length != 0) { if (text2.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1) { ErrorUtilities.VerifyThrowArgument(false, "Csc.AssemblyAliasContainsIllegalCharacters", taskItem.ItemSpec, text2); } if (string.Compare("global", text2, StringComparison.OrdinalIgnoreCase) == 0) { commandLine.AppendSwitchIfNotNull(switchName, taskItem.ItemSpec); } else { commandLine.AppendSwitchAliased(switchName, text2, taskItem.ItemSpec); } } } } } }