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


C# CommandLineBuilderExtension.AppendSwitchAliased方法代码示例

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


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

示例1: AddReferencesToCommandLine

 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);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:41,代码来源:Csc.cs

示例2: foreach

        /// <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);
//.........这里部分代码省略.........
开发者ID:JamesLinus,项目名称:msbuild,代码行数:101,代码来源:Csc.cs

示例3: AddReferencesToCommandLine

 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);
                     }
                 }
             }
         }
     }
 }
开发者ID:revitalyr,项目名称:msbuild-jsctask,代码行数:57,代码来源:Csc.cs


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