AppendWhenTrue() private méthode

private AppendWhenTrue ( string switchName, System bag, string parameterName ) : void
switchName string
bag System
parameterName string
Résultat void
Exemple #1
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());
        }
Exemple #2
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();
        }
Exemple #3
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);
                }
            }
        }
Exemple #4
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);
                }
            }

        }
Exemple #5
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();
 }