Beispiel #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. Defaults to one minute.</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 async 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);
            using (var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(1)))
            {
                await AssertStartAsync(
                    project.DirectoryPath,
                    "dotnet",
                    $"publish {noRestoreArgument} {frameworkArgument} {runtimeArgument} --output {project.PublishDirectoryPath}",
                    showShellWindow,
                    cancellationTokenSource.Token)
                .ConfigureAwait(false);
            }
        }
Beispiel #2
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)));
        }
Beispiel #3
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            var task = DirectoryExtensions.TryDeleteDirectory(this.DirectoryPath);

            task.Wait();
            if (!task.Result)
            {
                Debug.WriteLine($"Failed to delete directory {this.DirectoryPath}");
            }
        }
        /// <summary>
        /// Disposes the managed resources implementing <see cref="IDisposable" />.
        /// </summary>
        protected override void DisposeManaged()
        {
            var task = DirectoryExtensions.TryDeleteDirectoryAsync(this.DirectoryPath);

#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits. TODO: Use IAsyncDisposable in .NET Core 3.0.
            task.Wait();
            if (!task.Result)
            {
                Debug.WriteLine($"Failed to delete directory {this.DirectoryPath}");
            }
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits. TODO: Use IAsyncDisposable in .NET Core 3.0.
        }
Beispiel #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)));
        }
Beispiel #6
0
 /// <summary>
 /// Reinitialises the dotnet new command.
 /// </summary>
 /// <param name="timeout">The timeout. Defaults to one minute.</param>
 /// <param name="showShellWindow">if set to <c>true</c> show the shell window instead of logging to output.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 public static async Task ReinitialiseAsync(TimeSpan?timeout = null, bool showShellWindow = false)
 {
     using (var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(1)))
     {
         await ProcessExtensions
         .StartAsync(
             DirectoryExtensions.GetCurrentDirectory(),
             "dotnet",
             $"new --debug:reinit",
             showShellWindow,
             cancellationTokenSource.Token)
         .ConfigureAwait(false);
     }
 }
        /// <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)));
        }
Beispiel #8
0
        /// <summary>
        /// Installs a template from the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="timeout">The timeout. Defaults to one minute.</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 async Task InstallAsync(string source, TimeSpan?timeout = null, bool showShellWindow = false)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            using (var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(1)))
            {
                await ProcessExtensions
                .StartAsync(
                    DirectoryExtensions.GetCurrentDirectory(),
                    "dotnet",
                    $"new --install \"{source}\"",
                    showShellWindow,
                    cancellationTokenSource.Token)
                .ConfigureAwait(false);
            }
        }
Beispiel #9
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));
Beispiel #10
0
 /// <summary>
 /// Creates a new <see cref="TempDirectory"/>.
 /// </summary>
 /// <returns>The temporary directory.</returns>
 public static TempDirectory NewTempDirectory() => new TempDirectory(DirectoryExtensions.GetTempDirectoryPath());
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TempDirectory"/> class.
 /// </summary>
 /// <param name="directoryPath">The temporary directory path.</param>
 public TempDirectory(string directoryPath)
 {
     this.DirectoryPath = directoryPath;
     DirectoryExtensions.CheckCreate(this.DirectoryPath);
 }