コード例 #1
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);
     }
 }
コード例 #2
0
        private static async Task AssertStartAsync(
            string workingDirectory,
            string fileName,
            string arguments,
            CancellationToken cancellationToken)
        {
            var(processResult, message) = await ProcessExtensions.StartAsync(
                workingDirectory,
                fileName,
                arguments,
                cancellationToken).ConfigureAwait(false);

            if (processResult != ProcessResult.Succeeded)
            {
                throw new Exception(message);
            }
        }
コード例 #3
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. 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 project created from a project template.</returns>
        public static async Task <Project> DotnetNewAsync(
            this TempDirectory tempDirectory,
            string templateName,
            string name = null,
            IDictionary <string, string> arguments = null,
            TimeSpan?timeout     = null,
            bool showShellWindow = false)
        {
            if (tempDirectory is null)
            {
                throw new ArgumentNullException(nameof(tempDirectory));
            }

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

            if (name != null)
            {
                stringBuilder.Append($" --name \"{name}\"");
            }

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

            using (var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(1)))
            {
                await ProcessExtensions
                .StartAsync(
                    tempDirectory.DirectoryPath,
                    "dotnet",
                    stringBuilder.ToString(),
                    showShellWindow,
                    cancellationTokenSource.Token)
                .ConfigureAwait(false);
            }

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

            return(new Project(name, projectDirectoryPath, publishDirectoryPath));
        }
コード例 #4
0
ファイル: DotnetNew.cs プロジェクト: avjolsakaj/Framework
        /// <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);
            }
        }
コード例 #5
0
ファイル: DotnetNew.cs プロジェクト: khawaja74/Framework
 /// <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));