Пример #1
0
        /// <summary>
        /// Runs 'dotnet publish' on the specified project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="framework">The framework.</param>
        /// <param name="runtime">The runtime.</param>
        /// <param name="noRestore">Whether to restore the project.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="showShellWindow">if set to <c>true</c> show the shell window instead of logging to output.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task DotnetPublishAsync(
            this Project project,
            string framework     = null,
            string runtime       = null,
            bool?noRestore       = true,
            TimeSpan?timeout     = null,
            bool showShellWindow = false)
        {
            if (project is null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var frameworkArgument = framework is null ? null : $"--framework {framework}";
            var runtimeArgument   = runtime is null ? null : $"--self-contained --runtime {runtime}";
            var noRestoreArgument = noRestore is null ? null : "--no-restore";

            DirectoryExtensions.CheckCreate(project.PublishDirectoryPath);
            return(AssertStartAsync(
                       project.DirectoryPath,
                       "dotnet",
                       $"publish {noRestoreArgument} {frameworkArgument} {runtimeArgument} --output {project.PublishDirectoryPath}",
                       showShellWindow,
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #2
0
        /// <summary>
        /// Runs 'dotnet new' with the specified arguments.
        /// </summary>
        /// <param name="tempDirectory">The temporary directory.</param>
        /// <param name="templateName">Name of the 'dotnet new' template to create.</param>
        /// <param name="name">The name of the project to create from the template.</param>
        /// <param name="arguments">The custom arguments to pass to the template.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>A project created from a project template.</returns>
        public static async Task <Project> DotnetNewAsync(
            this TempDirectory tempDirectory,
            string templateName,
            string name,
            IDictionary <string, string> arguments = null,
            TimeSpan?timeout = null)
        {
            if (tempDirectory == null)
            {
                throw new ArgumentNullException(nameof(tempDirectory));
            }

            var stringBuilder = new StringBuilder($"new {templateName} --name \"{name}\"");

            if (arguments != null)
            {
                foreach (var argument in arguments)
                {
                    stringBuilder.Append($" --{argument.Key} \"{argument.Value}\"");
                }
            }

            await ProcessExtensions
            .StartAsync(
                tempDirectory.DirectoryPath,
                "dotnet",
                stringBuilder.ToString(),
                CancellationTokenFactory.GetCancellationToken(timeout))
            .ConfigureAwait(false);

            var projectDirectoryPath = Path.Combine(tempDirectory.DirectoryPath, name);
            var publishDirectoryPath = Path.Combine(projectDirectoryPath, "Publish");

            return(new Project(name, projectDirectoryPath, publishDirectoryPath));
        }
Пример #3
0
        /// <summary>
        /// Runs 'dotnet build' on the specified project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="noRestore">Whether to restore the project.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task DotnetBuild(this Project project, bool?noRestore = true, TimeSpan?timeout = null)
        {
            var noRestoreArgument = noRestore == null ? null : "--no-restore";

            return(AssertStartAsync(
                       project.DirectoryPath,
                       "dotnet",
                       $"build {noRestoreArgument}",
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #4
0
        /// <summary>
        /// Runs 'dotnet restore' on the specified project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task DotnetRestoreAsync(this Project project, TimeSpan?timeout = null)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            return(AssertStartAsync(
                       project.DirectoryPath,
                       "dotnet",
                       "restore",
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #5
0
        /// <summary>
        /// Installs a template from the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task InstallAsync(string source, TimeSpan?timeout = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(ProcessExtensions.StartAsync(
                       DirectoryExtensions.GetCurrentDirectory(),
                       "dotnet",
                       $"new --install \"{source}\"",
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #6
0
        /// <summary>
        /// Runs 'dotnet publish' on the specified project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="framework">The framework.</param>
        /// <param name="runtime">The runtime.</param>
        /// <param name="noRestore">Whether to restore the project.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task DotnetPublish(
            this Project project,
            string framework = null,
            string runtime   = null,
            bool?noRestore   = true,
            TimeSpan?timeout = null)
        {
            var frameworkArgument = framework == null ? null : $"--framework {framework}";
            var runtimeArgument   = runtime == null ? null : $"--self-contained --runtime {runtime}";
            var noRestoreArgument = noRestore == null ? null : "--no-restore";

            DirectoryExtensions.CheckCreate(project.PublishDirectoryPath);
            return(AssertStartAsync(
                       project.DirectoryPath,
                       "dotnet",
                       $"publish {noRestoreArgument} {frameworkArgument} {runtimeArgument} --output {project.PublishDirectoryPath}",
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #7
0
        /// <summary>
        /// Runs 'dotnet build' on the specified project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="noRestore">Whether to restore the project.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="showShellWindow">if set to <c>true</c> show the shell window instead of logging to output.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task DotnetBuildAsync(
            this Project project,
            bool?noRestore       = true,
            TimeSpan?timeout     = null,
            bool showShellWindow = false)
        {
            if (project is null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var noRestoreArgument = noRestore is null ? null : "--no-restore";

            return(AssertStartAsync(
                       project.DirectoryPath,
                       "dotnet",
                       $"build {noRestoreArgument}",
                       showShellWindow,
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #8
0
 /// <summary>
 /// Installs a template from the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="timeout">The timeout.</param>
 /// <returns>A task representing the operation.</returns>
 public static Task Install(string source, TimeSpan?timeout = null) =>
 ProcessExtensions.StartAsync(
     DirectoryExtensions.GetCurrentDirectory(),
     "dotnet",
     $"new --install \"{source}\"",
     CancellationTokenFactory.GetCancellationToken(timeout));
Пример #9
0
 /// <summary>
 /// Runs 'dotnet restore' on the specified project.
 /// </summary>
 /// <param name="project">The project.</param>
 /// <param name="timeout">The timeout.</param>
 /// <returns>A task representing the operation.</returns>
 public static Task DotnetRestore(this Project project, TimeSpan?timeout = null) =>
 AssertStartAsync(
     project.DirectoryPath,
     "dotnet",
     "restore",
     CancellationTokenFactory.GetCancellationToken(timeout));