Пример #1
0
        internal async Task <ProcessEx> RunDotNetEfUpdateDatabaseAsync()
        {
            var assembly = typeof(ProjectFactoryFixture).Assembly;

            var dotNetEfFullPath = assembly.GetCustomAttributes <AssemblyMetadataAttribute>()
                                   .First(attribute => attribute.Key == "DotNetEfFullPath")
                                   .Value;

            var args = $"\"{dotNetEfFullPath}\" --verbose --no-build database update";

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

            try
            {
                var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), args);
                await result.Exited;
                return(result);
            }
            finally
            {
                DotNetNewLock.Release();
            }
        }
Пример #2
0
        internal async Task <ProcessResult> RunDotNetEfUpdateDatabaseAsync()
        {
            var assembly = typeof(ProjectFactoryFixture).Assembly;

            var args = "--verbose --no-build database update";

            // 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");
                var command = DotNetMuxer.MuxerPathOrDefault();
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DotNetEfFullPath")))
                {
                    args = $"\"{DotNetEfFullPath}\" " + args;
                }
                else
                {
                    command = "dotnet-ef";
                }

                using var result = ProcessEx.Run(Output, TemplateOutputDir, command, args);
                await result.Exited;
                return(new ProcessResult(result));
            }
            finally
            {
                DotNetNewLock.Release();
                Output.WriteLine("Released DotNetNewLock");
            }
        }
Пример #3
0
        internal async Task <ProcessEx> RunDotNetEfCreateMigrationAsync(string migrationName)
        {
            var args = $"--verbose --no-build migrations add {migrationName}";

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

            try
            {
                var command = DotNetMuxer.MuxerPathOrDefault();
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DotNetEfFullPath")))
                {
                    args = $"\"{DotNetEfFullPath}\" " + args;
                }
                else
                {
                    command = "dotnet-ef";
                }

                var result = ProcessEx.Run(Output, TemplateOutputDir, command, args);
                await result.Exited;
                return(result);
            }
            finally
            {
                DotNetNewLock.Release();
            }
        }
Пример #4
0
        internal async Task <ProcessEx> RunDotNetNewAsync(string templateName, string auth = null, string language = null, bool useLocalDB = false, bool noHttps = false, string[] args = null)
        {
            var hiveArg   = $"--debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
            var argString = $"new {templateName} {hiveArg}";

            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
            {
                var execution = ProcessEx.Run(Output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), argString);
                await execution.Exited;
                return(execution);
            }
            finally
            {
                DotNetNewLock.Release();
            }
        }
Пример #5
0
        internal async Task <ProcessEx> RunDotNetEfUpdateDatabaseAsync()
        {
            var args = $"\"{DotNetEfFullPath}\" --verbose --no-build database update";

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

            try
            {
                var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), args);
                await result.Exited;
                return(result);
            }
            finally
            {
                DotNetNewLock.Release();
            }
        }
Пример #6
0
        internal async Task <ProcessResult> RunDotNetNewAsync(
            string templateName,
            string auth     = null,
            string language = null,
            bool useLocalDB = false,
            bool noHttps    = false,
            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;
                return(new ProcessResult(execution));
            }
            finally
            {
                DotNetNewLock.Release();
                Output.WriteLine("Released DotNetNewLock");
            }
        }