Esempio n. 1
0
        public static string GetFailedProcessMessage(string step, Project project, ProcessResult processResult)
        {
            return $@"Project {project.ProjectArguments} failed to {step}. Exit code {processResult.ExitCode}.
{processResult.Process}\nStdErr: {processResult.Error}\nStdOut: {processResult.Output}";
        }
Esempio n. 2
0
        internal async Task <ProcessResult> RunDotNetNewAsync(
            string templateName,
            string auth              = null,
            string language          = null,
            bool useLocalDB          = false,
            bool noHttps             = false,
            bool errorOnRestoreError = true,
            string[] args            = null,
            // Used to set special options in MSBuild
            IDictionary <string, string> environmentVariables = null)
        {
            var hiveArg   = $" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
            var argString = $"new {templateName} {hiveArg}";

            environmentVariables ??= new Dictionary <string, string>();
            if (!string.IsNullOrEmpty(auth))
            {
                argString += $" --auth {auth}";
            }

            if (!string.IsNullOrEmpty(language))
            {
                argString += $" -lang {language}";
            }

            if (useLocalDB)
            {
                argString += $" --use-local-db";
            }

            if (noHttps)
            {
                argString += $" --no-https";
            }

            if (args != null)
            {
                foreach (var arg in args)
                {
                    argString += " " + arg;
                }
            }

            // Save a copy of the arguments used for better diagnostic error messages later.
            // We omit the hive argument and the template output dir as they are not relevant and add noise.
            ProjectArguments = argString.Replace(hiveArg, "");

            argString += $" -o {TemplateOutputDir}";

            // Only run one instance of 'dotnet new' at once, as a workaround for
            // https://github.com/aspnet/templating/issues/63

            await DotNetNewLock.WaitAsync();

            try
            {
                Output.WriteLine("Acquired DotNetNewLock");

                if (Directory.Exists(TemplateOutputDir))
                {
                    Output.WriteLine($"Template directory already exists, deleting contents of {TemplateOutputDir}");
                    Directory.Delete(TemplateOutputDir, recursive: true);
                }

                using var execution = ProcessEx.Run(Output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
                await execution.Exited;

                var result = new ProcessResult(execution);

                // Because dotnet new automatically restores but silently ignores restore errors, need to handle restore errors explicitly
                if (errorOnRestoreError && (execution.Output.Contains("Restore failed.") || execution.Error.Contains("Restore failed.")))
                {
                    result.ExitCode = -1;
                }

                return(result);
            }
            finally
            {
                DotNetNewLock.Release();
                Output.WriteLine("Released DotNetNewLock");
            }
        }