public string GetPublishArguments()

in src/Amazon.Lambda.Tools/LambdaDotNetCLIWrapper.cs [274:377]


        public string GetPublishArguments(string projectLocation, 
            string outputLocation, 
            string targetFramework, 
            string configuration, 
            string msbuildParameters, 
            string architecture, 
            IList<string> publishManifests,
            bool isNativeAot = false,
            string projectLocationInsideContainer = null)
        {
            StringBuilder arguments = new StringBuilder("publish");
            if (!string.IsNullOrEmpty(projectLocationInsideContainer))
            {
                arguments.Append($" \"{projectLocationInsideContainer}\"");
            }
            else if (!string.IsNullOrEmpty(projectLocation))
            {
                arguments.Append($" \"{projectLocation}\"");
            }

            if (!string.IsNullOrEmpty(outputLocation))
            {
                arguments.Append($" --output \"{outputLocation}\"");
            }

            if (!string.IsNullOrEmpty(configuration))
            {
                arguments.Append($" --configuration \"{configuration}\"");
            }

            if (!string.IsNullOrEmpty(targetFramework))
            {
                arguments.Append($" --framework \"{targetFramework}\"");
            }

            if (!string.IsNullOrEmpty(msbuildParameters))
            {
                arguments.Append($" {msbuildParameters}");
            }

            if (!string.Equals("netcoreapp1.0", targetFramework, StringComparison.OrdinalIgnoreCase))
            {
                arguments.Append(" /p:GenerateRuntimeConfigurationFiles=true");

                // Define an action to set the runtime and self-contained switches.
                var applyRuntimeSwitchAction = (Action)(() =>
                {
                    if (msbuildParameters == null ||
                        msbuildParameters.IndexOf("--runtime", StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        arguments.Append($" --runtime {LambdaUtilities.DetermineRuntimeParameter(targetFramework, architecture)}");
                    }

                    if (!Utilities.HasExplicitSelfContainedFlag(projectLocation, msbuildParameters))
                    {
                        arguments.Append($" --self-contained {isNativeAot} ");
                    }
                });

                // This is here to not change existing behavior for the 2.0 and 2.1 runtimes. For those runtimes if
                // cshtml files are being used we need to support that cshtml being compiled at runtime. In order to do that we
                // need to not turn PreserveCompilationContext which provides reference assemblies to the runtime
                // compilation and not set a runtime.
                //
                // If there are no cshtml then disable PreserveCompilationContext to reduce package size and continue
                // to use the same runtime identifier that we used when those runtimes were launched.
                if (new string[] { "netcoreapp2.0", "netcoreapp2.1" }.Contains(targetFramework))
                {
                    if (Directory.GetFiles(projectLocation, "*.cshtml", SearchOption.AllDirectories).Length == 0)
                    {
                        applyRuntimeSwitchAction();

                        if (string.IsNullOrEmpty(msbuildParameters) ||
                            !msbuildParameters.Contains("PreserveCompilationContext"))
                        {
                            _logger?.WriteLine("... Disabling compilation context to reduce package size. If compilation context is needed pass in the \"/p:PreserveCompilationContext=false\" switch.");
                            arguments.Append(" /p:PreserveCompilationContext=false");
                        }
                    }
                }
                else
                {
                    applyRuntimeSwitchAction();
                }

                // If we have a manifest of packages already deploy in target deployment environment then write it to disk and add the 
                // command line switch
                if (publishManifests != null && publishManifests.Count > 0)
                {
                    foreach (var manifest in publishManifests)
                    {
                        arguments.Append($" --manifest \"{manifest}\"");
                    }
                }

                if (isNativeAot)
                {
                    // StripSymbols will greatly reduce output binary size with Native AOT
                    arguments.Append(" /p:StripSymbols=true");
                }
            }

            return arguments.ToString();
        }