Inheritance: Microsoft.Build.Tasks.CommandLineBuilderExtension
Beispiel #1
0
        protected override string GenerateResponseFileCommands()
        {
            var commandLine = new XSharpCommandLineBuilder(useCRLF);

            this.AddResponseFileCommands(commandLine);
            return(commandLine.ToString());
        }
Beispiel #2
0
        protected override string GenerateCommandLineCommands()
        {
            var commandLine = new XSharpCommandLineBuilder(false);

            commandLine.AppendWhenTrue("/noconfig", base.Bag, nameof(NoConfig));
            commandLine.AppendWhenTrue("/shared", base.Bag, nameof(UseSharedCompilation));
            return(commandLine.ToString());
        }
Beispiel #3
0
        internal void AddVOCompatibilityCommands(XSharpCommandLineBuilder commandline)
        {
            // VO Compatibility switches

            if (NS)     // Add Default Namespace
            {
                commandline.AppendSwitch("/ns:" + this.RootNameSpace);
            }
            commandline.AppendPlusOrMinusSwitch("/az", base.Bag, nameof(AZ));
            //commandline.AppendPlusOrMinusSwitch("/cs", base.Bag, nameof(CS));
            commandline.AppendPlusOrMinusSwitch("/ins", base.Bag, nameof(INS));
            commandline.AppendPlusOrMinusSwitch("/lb", base.Bag, nameof(LB));
            commandline.AppendPlusOrMinusSwitch("/namedarguments", base.Bag, nameof(NamedArgs));
            commandline.AppendPlusOrMinusSwitch("/memvar", base.Bag, nameof(MemVar));
            commandline.AppendPlusOrMinusSwitch("/undeclared", base.Bag, nameof(Undeclared));
            commandline.AppendPlusOrMinusSwitch("/ovf", base.Bag, nameof(OVF));
            commandline.AppendPlusOrMinusSwitch("/ppo", base.Bag, nameof(PPO));
            commandline.AppendPlusOrMinusSwitch("/vo1", base.Bag, nameof(VO1));
            commandline.AppendPlusOrMinusSwitch("/vo2", base.Bag, nameof(VO2));
            commandline.AppendPlusOrMinusSwitch("/vo3", base.Bag, nameof(VO3));
            commandline.AppendPlusOrMinusSwitch("/vo4", base.Bag, nameof(VO4));
            commandline.AppendPlusOrMinusSwitch("/vo5", base.Bag, nameof(VO5));
            commandline.AppendPlusOrMinusSwitch("/vo6", base.Bag, nameof(VO6));
            commandline.AppendPlusOrMinusSwitch("/vo7", base.Bag, nameof(VO7));
            commandline.AppendPlusOrMinusSwitch("/vo8", base.Bag, nameof(VO8));
            commandline.AppendPlusOrMinusSwitch("/vo9", base.Bag, nameof(VO9));
            commandline.AppendPlusOrMinusSwitch("/vo10", base.Bag, nameof(VO10));
            //commandline.AppendPlusOrMinusSwitch("/vo11", base.Bag, nameof(VO11));
            commandline.AppendPlusOrMinusSwitch("/vo12", base.Bag, nameof(VO12));
            commandline.AppendPlusOrMinusSwitch("/vo13", base.Bag, nameof(VO13));
            commandline.AppendPlusOrMinusSwitch("/vo14", base.Bag, nameof(VO14));
            commandline.AppendPlusOrMinusSwitch("/vo15", base.Bag, nameof(VO15));
            commandline.AppendPlusOrMinusSwitch("/vo16", base.Bag, nameof(VO16));
            commandline.AppendPlusOrMinusSwitch("/xpp1", base.Bag, nameof(XPP1));
            commandline.AppendPlusOrMinusSwitch("/xpp2", base.Bag, nameof(XPP2));

            // User-defined CommandLine Option (in order to support switches unknown at that time)
            // cannot use appendswitch because it will quote the string when there are embedded spaces
            if (!String.IsNullOrEmpty(this.CommandLineOption))
            {
                commandline.AppendTextUnquoted(this.CommandLineOption);
            }
            if (this.IncludePaths?.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var s in this.IncludePaths)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(';');
                    }
                    sb.Append(s);
                }
                string path = sb.ToString();
                path = path.Replace(@"\\", @"\");
                commandline.AppendTextUnquoted("/i:\"" + path + "\"");
            }
        }
Beispiel #4
0
 /// <summary>
 /// Adds a "/features:" switch to the command line for each provided feature.
 /// </summary>
 internal static void AddFeatures(XSharpCommandLineBuilder commandLine, string features)
 {
     if (string.IsNullOrEmpty(features))
     {
         return;
     }
     // Todo: Implement /features commandline option
     //foreach (var feature in CompilerOptionParseUtilities.ParseFeatureFromMSBuild(features))
     //{
     //    commandLine.AppendSwitchIfNotNull("/features:", feature.Trim());
     //}
 }
Beispiel #5
0
        protected void AddResponseFileCommandsImpl(CommandLineBuilderExtension cmdline)
        {
            XSharpCommandLineBuilder commandLine = (XSharpCommandLineBuilder)cmdline;

            // The managed compiler command line options are called from the cscCompiler options
            if (this.Dialect?.Length > 0)
            {
                cmdline.AppendTextUnquoted("/dialect:" + this.Dialect);
            }
            AddCscCompilerCommands(commandLine);
            AddVOCompatibilityCommands(commandLine);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a "/analyzer:" switch to the command line for each provided analyzer.
        /// </summary>
        internal static void AddAnalyzersToCommandLine(XSharpCommandLineBuilder commandLine, ITaskItem[] analyzers)
        {
            // If there were no analyzers passed in, don't add any /analyzer: switches
            // on the command-line.
            if (analyzers == null)
            {
                return;
            }

            foreach (ITaskItem analyzer in analyzers)
            {
                commandLine.AppendSwitchIfNotNull("/analyzer:", analyzer.ItemSpec);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Adds a "/additionalfile:" switch to the command line for each additional file.
        /// </summary>
        private void AddAdditionalFilesToCommandLine(XSharpCommandLineBuilder commandLine)
        {
            // If there were no additional files passed in, don't add any /additionalfile: switches
            // on the command-line.
            if (AdditionalFiles == null)
            {
                return;
            }

            foreach (ITaskItem additionalFile in AdditionalFiles)
            {
                commandLine.AppendSwitchIfNotNull("/additionalfile:", additionalFile.ItemSpec);
            }
        }
Beispiel #8
0
 protected override string GenerateResponseFileCommands()
 {
     CommandLineBuilderExtension commandLine = new XSharpCommandLineBuilder();
     this.AddResponseFileCommands(commandLine);
     return commandLine.ToString();
 }
Beispiel #9
0
        internal void AddVOCompatibilityCommands(XSharpCommandLineBuilder commandline)
        {
            // VO Compatibility switches

            if (NS)     // Add Default Namespace
            {
                commandline.AppendSwitch("\n/ns:" + this.RootNameSpace);
            }
            commandline.AppendPlusOrMinusSwitch("/az", base.Bag, nameof(AZ));
            commandline.AppendPlusOrMinusSwitch("/cs", base.Bag, nameof(CS));
            commandline.AppendPlusOrMinusSwitch("/ins", base.Bag, nameof(INS));
            if (this.IncludePaths?.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var s in this.IncludePaths)
                {
                    if (sb.Length > 0)
                        sb.Append(';');
                    sb.Append(s);
                }
                commandline.AppendTextUnquoted(" /i:\"" + sb.ToString()+"\"");
            }
            commandline.AppendPlusOrMinusSwitch("/lb", base.Bag, nameof(LB));
            commandline.AppendPlusOrMinusSwitch("/ovf", base.Bag, nameof(OVF));
            commandline.AppendPlusOrMinusSwitch("/ppo", base.Bag, nameof(PPO));
            commandline.AppendPlusOrMinusSwitch("/vo1", base.Bag, nameof(VO1));
            commandline.AppendPlusOrMinusSwitch("/vo2", base.Bag, nameof(VO2));
            commandline.AppendPlusOrMinusSwitch("/vo3", base.Bag, nameof(VO3));
            commandline.AppendPlusOrMinusSwitch("/vo4", base.Bag, nameof(VO4));
            commandline.AppendPlusOrMinusSwitch("/vo5", base.Bag, nameof(VO5));
            commandline.AppendPlusOrMinusSwitch("/vo6", base.Bag, nameof(VO6));
            commandline.AppendPlusOrMinusSwitch("/vo7", base.Bag, nameof(VO7));
            commandline.AppendPlusOrMinusSwitch("/vo8", base.Bag, nameof(VO8));
            commandline.AppendPlusOrMinusSwitch("/vo9", base.Bag, nameof(VO9));
            commandline.AppendPlusOrMinusSwitch("/vo10", base.Bag, nameof(VO10));
            commandline.AppendPlusOrMinusSwitch("/vo11", base.Bag, nameof(VO11));
            commandline.AppendPlusOrMinusSwitch("/vo12", base.Bag, nameof(VO12));
            commandline.AppendPlusOrMinusSwitch("/vo13", base.Bag, nameof(VO13));
            commandline.AppendPlusOrMinusSwitch("/vo14", base.Bag, nameof(VO14));
            commandline.AppendPlusOrMinusSwitch("/vo15", base.Bag, nameof(VO15));
            // User-defined CommandLine Option (in order to support switches unknown at that time)
            // cannot use appendswitch because it will quote the string when there are embedded spaces
            if(!String.IsNullOrEmpty(this.CommandLineOption))
            {
                commandline.AppendTextUnquoted("\n" + this.CommandLineOption);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Mostly copied from the csc task in Roslyn
        /// </summary>
        /// <param name="commandLine"></param>
        internal void AddCscCompilerCommands(XSharpCommandLineBuilder commandLine)
        {
            commandLine.AppendSwitchIfNotNull("/lib:", AdditionalLibPaths, ",");
            commandLine.AppendPlusOrMinusSwitch("/unsafe", base.Bag, nameof(AllowUnsafeBlocks));
            commandLine.AppendPlusOrMinusSwitch("/checked", base.Bag, nameof(CheckForOverflowUnderflow));
            commandLine.AppendSwitchWithSplitting("/nowarn:", DisabledWarnings, ",", ';', ',');
            //commandLine.AppendWhenTrue("/fullpaths", base.Bag, nameof(GenerateFullPaths));
            commandLine.AppendSwitch("/fullpaths");
            commandLine.AppendSwitchIfNotNull("/langversion:", LangVersion);
            commandLine.AppendSwitchIfNotNull("/moduleassemblyname:", ModuleAssemblyName);
            commandLine.AppendSwitchIfNotNull("/pdb:", PdbFile);
            commandLine.AppendPlusOrMinusSwitch("/nostdlib", base.Bag, nameof(NoStandardLib));
            commandLine.AppendPlusOrMinusSwitch("/nostddefs", base.Bag, nameof(NoStandardDefs));
            if (!NoStandardDefs && !string.IsNullOrEmpty(StandardDefs))
            {
                commandLine.AppendSwitchIfNotNull("/stddefs:", StandardDefs);
            }
            commandLine.AppendSwitchIfNotNull("/platform:", PlatformWith32BitPreference);
            commandLine.AppendSwitchIfNotNull("/errorreport:", ErrorReport);
            commandLine.AppendSwitchWithInteger("/warn:", base.Bag, nameof(WarningLevel));
            commandLine.AppendSwitchIfNotNull("/doc:", DocumentationFile);
            commandLine.AppendSwitchIfNotNull("/baseaddress:", BaseAddress);
            commandLine.AppendSwitchUnquotedIfNotNull("/define:", Utilities.GetDefineConstantsSwitch(DefineConstants, Log));
            commandLine.AppendSwitchIfNotNull("/win32res:", Win32Resource);
            commandLine.AppendSwitchIfNotNull("/main:", MainEntryPoint);
            commandLine.AppendSwitchIfNotNull("/appconfig:", ApplicationConfiguration);
            commandLine.AppendWhenTrue("/errorendlocation", base.Bag, nameof(ErrorEndLocation));
            commandLine.AppendSwitchIfNotNull("/preferreduilang:", PreferredUILang);
            commandLine.AppendPlusOrMinusSwitch("/highentropyva", base.Bag, nameof(HighEntropyVA));
            //// If not design time build and the globalSessionGuid property was set then add a -globalsessionguid:<guid>
            //bool designTime = false;
            //if (HostObject != null)
            //{
            //    var csHost = HostObject as ICscHostObject;
            //    designTime = csHost.IsDesignTime();
            //}
            //if (!designTime)
            //{
            //    if (!string.IsNullOrWhiteSpace(VsSessionGuid))
            //    {
            //        commandLine.AppendSwitchIfNotNull("/sqmsessionguid:", VsSessionGuid);
            //    }
            //}

            AddReferencesToCommandLine(commandLine, References);
            AddManagedCompilerCommands(commandLine);
            // This should come after the "TreatWarningsAsErrors" flag is processed (in managedcompiler.cs).
            // Because if TreatWarningsAsErrors=false, then we'll have a /warnaserror- on the command-line,
            // and then any specific warnings that should be treated as errors should be specified with
            // /warnaserror+:<list> after the /warnaserror- switch.  The order of the switches on the command-line
            // does matter.
            //
            // Note that
            //      /warnaserror+
            // is just shorthand for:
            //      /warnaserror+:<all possible warnings>
            //
            // Similarly,
            //      /warnaserror-
            // is just shorthand for:
            //      /warnaserror-:<all possible warnings>
            commandLine.AppendSwitchWithSplitting("/warnaserror+:", WarningsAsErrors, ",", ';', ',');
            commandLine.AppendSwitchWithSplitting("/warnaserror-:", WarningsNotAsErrors, ",", ';', ',');

            // It's a good idea for the response file to be the very last switch passed, just
            // from a predictability perspective.  It also solves the problem that a dogfooder
            // ran into, which is described in an email thread attached to bug VSWhidbey 146883.
            // See also bugs 177762 and 118307 for additional bugs related to response file position.
            if (ResponseFiles != null)
            {
                foreach (ITaskItem response in ResponseFiles)
                {
                    commandLine.AppendSwitchIfNotNull("@", response.ItemSpec);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Mostly copied from the csc task in Roslyn
        /// </summary>
        /// <param name="commandLine"></param>
        internal void AddCscCompilerCommands(XSharpCommandLineBuilder commandLine)
        {
            commandLine.AppendSwitchIfNotNull("/lib:", AdditionalLibPaths, ",");
            commandLine.AppendPlusOrMinusSwitch("/unsafe", base.Bag, nameof(AllowUnsafeBlocks));
            commandLine.AppendPlusOrMinusSwitch("/checked", base.Bag, nameof(CheckForOverflowUnderflow));
            commandLine.AppendSwitchWithSplitting("/nowarn:", DisabledWarnings, ",", ';', ',');
            //commandLine.AppendWhenTrue("/fullpaths", base.Bag, nameof(GenerateFullPaths));
            commandLine.AppendSwitch("/fullpaths");
            commandLine.AppendSwitchIfNotNull("/langversion:", LangVersion);
            commandLine.AppendSwitchIfNotNull("/moduleassemblyname:", ModuleAssemblyName);
            commandLine.AppendSwitchIfNotNull("/pdb:", PdbFile);
            commandLine.AppendPlusOrMinusSwitch("/nostdlib", base.Bag, nameof(NoStandardLib));
            commandLine.AppendSwitchIfNotNull("/platform:", Platform);
            commandLine.AppendSwitchIfNotNull("/errorreport:", ErrorReport);
            commandLine.AppendSwitchWithInteger("/warn:", base.Bag, nameof(WarningLevel));
            //commandLine.AppendSwitchIfNotNull("/doc:", DocumentationFile);
            commandLine.AppendSwitchIfNotNull("/baseaddress:", BaseAddress);
            commandLine.AppendSwitchUnquotedIfNotNull("/define:", Utilities.GetDefineConstantsSwitch(DefineConstants, Log));
            commandLine.AppendSwitchIfNotNull("/win32res:", Win32Resource);
            commandLine.AppendSwitchIfNotNull("/main:", MainEntryPoint);
            commandLine.AppendSwitchIfNotNull("/appconfig:", ApplicationConfiguration);
            commandLine.AppendWhenTrue("/errorendlocation", base.Bag, nameof(ErrorEndLocation));
            commandLine.AppendSwitchIfNotNull("/preferreduilang:", PreferredUILang);
            commandLine.AppendPlusOrMinusSwitch("/highentropyva", base.Bag, nameof(HighEntropyVA));
            //// If not design time build and the globalSessionGuid property was set then add a -globalsessionguid:<guid>
            //bool designTime = false;
            //if (HostObject != null)
            //{
            //    var csHost = HostObject as ICscHostObject;
            //    designTime = csHost.IsDesignTime();
            //}
            //if (!designTime)
            //{
            //    if (!string.IsNullOrWhiteSpace(VsSessionGuid))
            //    {
            //        commandLine.AppendSwitchIfNotNull("/sqmsessionguid:", VsSessionGuid);
            //    }
            //}

            AddReferencesToCommandLine(commandLine, References);
            AddManagedCompilerCommands(commandLine);
            // This should come after the "TreatWarningsAsErrors" flag is processed (in managedcompiler.cs).
            // Because if TreatWarningsAsErrors=false, then we'll have a /warnaserror- on the command-line,
            // and then any specific warnings that should be treated as errors should be specified with
            // /warnaserror+:<list> after the /warnaserror- switch.  The order of the switches on the command-line
            // does matter.
            //
            // Note that
            //      /warnaserror+
            // is just shorthand for:
            //      /warnaserror+:<all possible warnings>
            //
            // Similarly,
            //      /warnaserror-
            // is just shorthand for:
            //      /warnaserror-:<all possible warnings>
            commandLine.AppendSwitchWithSplitting("/warnaserror+:", WarningsAsErrors, ",", ';', ',');
            commandLine.AppendSwitchWithSplitting("/warnaserror-:", WarningsNotAsErrors, ",", ';', ',');

            // It's a good idea for the response file to be the very last switch passed, just 
            // from a predictability perspective.  It also solves the problem that a dogfooder
            // ran into, which is described in an email thread attached to bug VSWhidbey 146883.
            // See also bugs 177762 and 118307 for additional bugs related to response file position.
            if (ResponseFiles != null)
            {
                foreach (ITaskItem response in ResponseFiles)
                {
                    commandLine.AppendSwitchIfNotNull("@", response.ItemSpec);
                }
            }

        }
Beispiel #12
0
        /// <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>

        internal static void AddReferencesToCommandLine(XSharpCommandLineBuilder commandLine, ITaskItem[] references, bool isInteractive = false)
        {
            // If there were no references passed in, don't add any /reference: switches
            // on the command-line.
            if (references == null)
            {
                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 references)
            {
                // See if there was an "Alias" attribute on the reference.
                string aliasString = reference.GetMetadata("Aliases");


                string switchName = "/reference:";
                if (!isInteractive)
                {
                    bool embed = Utilities.TryConvertItemMetadataToBool(reference,
                                                                        "EmbedInteropTypes");

                    if (embed)
                    {
                        switchName = "/link:";
                    }
                }
                if (string.IsNullOrEmpty(aliasString))
                {
                    // 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 screw up the command-line parsing or could
                        // allow parameter injection.
                        if (trimmedAlias.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1)
                        {
                            throw new Exception("Alias contains illegal characters :" + 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);
                        }
                    }
                }
            }
        }
Beispiel #13
0
 /// <summary>
 /// Adds a "/features:" switch to the command line for each provided feature.
 /// </summary>
 internal static void AddFeatures(XSharpCommandLineBuilder commandLine, string features)
 {
     if (string.IsNullOrEmpty(features))
     {
         return;
     }
     // Todo: Implement /features commandline option
     //foreach (var feature in CompilerOptionParseUtilities.ParseFeatureFromMSBuild(features))
     //{
     //    commandLine.AppendSwitchIfNotNull("/features:", feature.Trim());
     //}
 }
Beispiel #14
0
        /// <summary>
        /// Adds a "/analyzer:" switch to the command line for each provided analyzer.
        /// </summary>
        internal static void AddAnalyzersToCommandLine(XSharpCommandLineBuilder commandLine, ITaskItem[] analyzers)
        {
            // If there were no analyzers passed in, don't add any /analyzer: switches
            // on the command-line.
            if (analyzers == null)
            {
                return;
            }

            foreach (ITaskItem analyzer in analyzers)
            {
                commandLine.AppendSwitchIfNotNull("/analyzer:", analyzer.ItemSpec);
            }
        }
Beispiel #15
0
        /// <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>

        internal static void AddReferencesToCommandLine(XSharpCommandLineBuilder commandLine, ITaskItem[] references, bool isInteractive = false)
        {
            // If there were no references passed in, don't add any /reference: switches
            // on the command-line.
            if (references == null)
            {
                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 references)
            {
                // See if there was an "Alias" attribute on the reference.
                string aliasString = reference.GetMetadata("Aliases");


                string switchName = "/reference:";
                if (!isInteractive)
                {
                    bool embed = Utilities.TryConvertItemMetadataToBool(reference,
                                                                        "EmbedInteropTypes");

                    if (embed)
                    {
                        switchName = "/link:";
                    }
                }
                if (string.IsNullOrEmpty(aliasString))
                {
                    // 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 screw up the command-line parsing or could
                        // allow parameter injection.
                        if (trimmedAlias.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1)
                        {
                            throw new Exception("Alias contains illegal characters :" + 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);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Mostly copied from the ManagedCompiler task in Roslyn
        /// </summary>
        /// <param name="commandLine"></param>

        internal void AddManagedCompilerCommands(XSharpCommandLineBuilder cmdline)
        {
            // If outputAssembly is not specified, then an "/out: <name>" option won't be added to
            // overwrite the one resulting from the OutputAssembly member of the CompilerParameters class.
            // In that case, we should set the outputAssembly member based on the first source file.
            XSharpCommandLineBuilder commandLine = (XSharpCommandLineBuilder)cmdline;
            if (
                    (OutputAssembly == null) &&
                    (Sources != null) &&
                    (Sources.Length > 0) &&
                    (ResponseFiles == null)    // The response file may already have a /out: switch in it, so don't try to be smart here.
                )
            {
                try
                {
                    OutputAssembly = new TaskItem(Path.GetFileNameWithoutExtension(Sources[0].ItemSpec));
                }
                catch (ArgumentException e)
                {
                    throw new ArgumentException(e.Message, "Sources");
                }
                if (string.Compare(TargetType, "library", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    OutputAssembly.ItemSpec += ".dll";
                }
                else if (string.Compare(TargetType, "module", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    OutputAssembly.ItemSpec += ".netmodule";
                }
                else
                {
                    OutputAssembly.ItemSpec += ".exe";
                }
            }
            commandLine.AppendSwitchIfNotNull("/addmodule:", AddModules, ",");
            commandLine.AppendSwitchWithInteger("/codepage:", base.Bag, nameof(CodePage));

            ConfigureDebugProperties();

            // The "DebugType" parameter should be processed after the "EmitDebugInformation" parameter
            // because it's more specific.  Order matters on the command-line, and the last one wins.
            // /debug+ is just a shorthand for /debug:full.  And /debug- is just a shorthand for /debug:none.

            commandLine.AppendPlusOrMinusSwitch("/debug", base.Bag, nameof(EmitDebugInformation));
            commandLine.AppendSwitchIfNotNull("/debug:", DebugType);

            commandLine.AppendPlusOrMinusSwitch("/delaysign", base.Bag, nameof(DelaySign));

            commandLine.AppendSwitchWithInteger("/filealign:", base.Bag, nameof(FileAlignment));
            commandLine.AppendSwitchIfNotNull("/keycontainer:", KeyContainer);
            commandLine.AppendSwitchIfNotNull("/keyfile:", KeyFile);
            // If the strings "LogicalName" or "Access" ever change, make sure to search/replace everywhere in vsproject.
            commandLine.AppendSwitchIfNotNull("/linkresource:", LinkResources, new string[] { "LogicalName", "Access" });
            commandLine.AppendWhenTrue("/nologo", base.Bag, nameof(NoLogo));
            commandLine.AppendWhenTrue("/nowin32manifest", base.Bag, nameof(NoWin32Manifest));
            commandLine.AppendPlusOrMinusSwitch("/optimize", base.Bag, nameof(Optimize));
            commandLine.AppendPlusOrMinusSwitch("/deterministic", base.Bag, nameof(Deterministic));
            commandLine.AppendSwitchIfNotNull("/pathmap:", PathMap);
            commandLine.AppendSwitchIfNotNull("/out:", OutputAssembly);
            commandLine.AppendSwitchIfNotNull("/ruleset:", CodeAnalysisRuleSet);
            commandLine.AppendSwitchIfNotNull("/errorlog:", ErrorLog);
            commandLine.AppendSwitchIfNotNull("/subsystemversion:", SubsystemVersion);
            commandLine.AppendWhenTrue("/reportanalyzer", base.Bag, nameof(ReportAnalyzer));
            // If the strings "LogicalName" or "Access" ever change, make sure to search/replace everywhere in vsproject.
            commandLine.AppendSwitchIfNotNull("/resource:", Resources, new string[] { "LogicalName", "Access" });
            commandLine.AppendSwitchIfNotNull("/target:", TargetType);
            commandLine.AppendPlusOrMinusSwitch("/warnaserror", base.Bag, nameof(TreatWarningsAsErrors));
            commandLine.AppendWhenTrue("/utf8output", base.Bag, nameof(Utf8Output));
            commandLine.AppendSwitchIfNotNull("/win32icon:", Win32Icon);
            commandLine.AppendSwitchIfNotNull("/win32manifest:", Win32Manifest);

            AddFeatures(commandLine, Features);
            AddAnalyzersToCommandLine(commandLine, Analyzers);
            AddAdditionalFilesToCommandLine(commandLine);

            // Append the sources.
            commandLine.AppendFileNamesIfNotNull(Sources, " ");

        }
Beispiel #17
0
        /// <summary>
        /// Adds a "/additionalfile:" switch to the command line for each additional file.
        /// </summary>
        private void AddAdditionalFilesToCommandLine(XSharpCommandLineBuilder commandLine)
        {
            // If there were no additional files passed in, don't add any /additionalfile: switches
            // on the command-line.
            if (AdditionalFiles == null)
            {
                return;
            }

            foreach (ITaskItem additionalFile in AdditionalFiles)
            {
                commandLine.AppendSwitchIfNotNull("/additionalfile:", additionalFile.ItemSpec);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Mostly copied from the ManagedCompiler task in Roslyn
        /// </summary>
        /// <param name="commandLine"></param>

        internal void AddManagedCompilerCommands(XSharpCommandLineBuilder cmdline)
        {
            // If outputAssembly is not specified, then an "/out: <name>" option won't be added to
            // overwrite the one resulting from the OutputAssembly member of the CompilerParameters class.
            // In that case, we should set the outputAssembly member based on the first source file.
            XSharpCommandLineBuilder commandLine = (XSharpCommandLineBuilder)cmdline;

            if (
                (OutputAssembly == null) &&
                (Sources != null) &&
                (Sources.Length > 0) &&
                (ResponseFiles == null)        // The response file may already have a /out: switch in it, so don't try to be smart here.
                )
            {
                try
                {
                    OutputAssembly = new TaskItem(Path.GetFileNameWithoutExtension(Sources[0].ItemSpec));
                }
                catch (ArgumentException e)
                {
                    throw new ArgumentException(e.Message, "Sources");
                }
                if (string.Compare(TargetType, "library", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    OutputAssembly.ItemSpec += ".dll";
                }
                else if (string.Compare(TargetType, "module", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    OutputAssembly.ItemSpec += ".netmodule";
                }
                else
                {
                    OutputAssembly.ItemSpec += ".exe";
                }
            }
            commandLine.AppendSwitchIfNotNull("/addmodule:", AddModules, ",");
            commandLine.AppendSwitchWithInteger("/codepage:", base.Bag, nameof(CodePage));
            ConfigureDebugProperties();

            // The "DebugType" parameter should be processed after the "EmitDebugInformation" parameter
            // because it's more specific.  Order matters on the command-line, and the last one wins.
            // /debug+ is just a shorthand for /debug:full.  And /debug- is just a shorthand for /debug:none.

            commandLine.AppendPlusOrMinusSwitch("/debug", base.Bag, nameof(EmitDebugInformation));
            commandLine.AppendSwitchIfNotNull("/debug:", DebugType);

            commandLine.AppendPlusOrMinusSwitch("/delaysign", base.Bag, nameof(DelaySign));

            commandLine.AppendSwitchWithInteger("/filealign:", base.Bag, nameof(FileAlignment));
            commandLine.AppendSwitchIfNotNull("/keycontainer:", KeyContainer);
            commandLine.AppendSwitchIfNotNull("/keyfile:", KeyFile);
            // If the strings "LogicalName" or "Access" ever change, make sure to search/replace everywhere in vsproject.
            commandLine.AppendSwitchIfNotNull("/linkresource:", LinkResources, new string[] { "LogicalName", "Access" });
            commandLine.AppendWhenTrue("/nologo", base.Bag, nameof(NoLogo));
            commandLine.AppendWhenTrue("/nowin32manifest", base.Bag, nameof(NoWin32Manifest));
            commandLine.AppendPlusOrMinusSwitch("/optimize", base.Bag, nameof(Optimize));
            commandLine.AppendPlusOrMinusSwitch("/deterministic", base.Bag, nameof(Deterministic));
            commandLine.AppendSwitchIfNotNull("/pathmap:", PathMap);
            commandLine.AppendSwitchIfNotNull("/out:", OutputAssembly);
            commandLine.AppendSwitchIfNotNull("/ruleset:", CodeAnalysisRuleSet);
            commandLine.AppendSwitchIfNotNull("/errorlog:", ErrorLog);
            commandLine.AppendSwitchIfNotNull("/subsystemversion:", SubsystemVersion);
            commandLine.AppendWhenTrue("/reportanalyzer", base.Bag, nameof(ReportAnalyzer));
            // If the strings "LogicalName" or "Access" ever change, make sure to search/replace everywhere in vsproject.
            if (VulcanCompatibleResources)
            {
                commandLine.AppendSwitchIfNotNull("/resource:", Resources, new string[] { });
            }
            else
            {
                commandLine.AppendSwitchIfNotNull("/resource:", Resources, new string[] { "LogicalName", "Access" });
            }

            commandLine.AppendSwitchIfNotNull("/target:", TargetType);
            commandLine.AppendPlusOrMinusSwitch("/warnaserror", base.Bag, nameof(TreatWarningsAsErrors));
            commandLine.AppendWhenTrue("/utf8output", base.Bag, nameof(Utf8Output));
            commandLine.AppendSwitchIfNotNull("/win32icon:", Win32Icon);
            commandLine.AppendSwitchIfNotNull("/win32manifest:", Win32Manifest);

            AddFeatures(commandLine, Features);
            AddAnalyzersToCommandLine(commandLine, Analyzers);
            AddAdditionalFilesToCommandLine(commandLine);

            // Append the sources.

            commandLine.AppendFileNamesIfNotNull(Sources, useCRLF ? "\n " : " ");
            commandLine.AppendNewLine();
        }
Beispiel #19
0
 protected override string GenerateCommandLineCommands()
 {
     var commandLine = new XSharpCommandLineBuilder();
     commandLine.AppendWhenTrue("/noconfig", base.Bag, nameof(NoConfig));
     commandLine.AppendWhenTrue("/shared", base.Bag, nameof(UseSharedCompilation));
     return commandLine.ToString();
 }