Exemplo n.º 1
0
        public async Task <ProcessRunner.ProcessResult> BuildAsync(ILogger logger, CancellationToken cancellationToken)
        {
            ThrowOnDisposed();

            string buildParams = $"build {GetNoRestoreParam(this.SdkVersion)}";

            return(await ProcessRunner.RunAsync("dotnet", buildParams, this.DirectoryPath, logger, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 2
0
        public static async Task <MSBuildProj> DotNetNewAsync(string fullPath, ILogger logger, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            MSBuildProj project = null;
            bool        ownsDir = false;

            if (fullPath == null)
            {
                throw new ArgumentNullException(nameof(fullPath));
            }
            fullPath = Path.GetFullPath(fullPath);

            string projectName      = Path.GetFileNameWithoutExtension(fullPath);
            string projectExtension = Path.GetExtension(fullPath);
            string projectDir       = Path.GetDirectoryName(fullPath);

            if (string.IsNullOrEmpty(projectName) || string.CompareOrdinal(projectExtension.ToLowerInvariant(), ".csproj") != 0)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Shared.Resources.ErrorFullPathNotAProjectFilePathFormat, fullPath));
            }

            if (File.Exists(fullPath))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Shared.Resources.ErrorProjectFileAlreadyExistsFormat, fullPath));
            }

            // ensure we have a working directory for the ProcessRunner (ProjectPropertyResolver).
            if (!Directory.Exists(projectDir))
            {
                Directory.CreateDirectory(projectDir);
                ownsDir = true;
            }

            var sdkVersion = await ProjectPropertyResolver.GetSdkVersionAsync(projectDir, logger, cancellationToken).ConfigureAwait(false);

            var dotnetNewParams = $"new console {GetNoRestoreParam(sdkVersion)} --force --type project --language C# --output . --name {projectName}";
            await ProcessRunner.RunAsync("dotnet", dotnetNewParams, projectDir, logger, cancellationToken).ConfigureAwait(false);

            project = await ParseAsync(File.ReadAllText(fullPath), fullPath, logger, cancellationToken).ConfigureAwait(false);

            project._ownsDirectory = ownsDir;

            project.SdkVersion = sdkVersion ?? string.Empty;
            project._isSaved   = true;

            return(project);
        }
Exemplo n.º 3
0
        internal async Task <ProcessRunner.ProcessResult> BoostrapSvcutilAsync(bool keepBootstrapperDir, ILogger logger, CancellationToken cancellationToken)
        {
            bool redirectOutput = false;

            if (this.Options.ToolContext == OperationalContext.Infrastructure)
            {
                redirectOutput = true;
            }

            ProcessRunner.ProcessResult result = null;

            using (await SafeLogger.WriteStartOperationAsync(logger, "Bootstrapping svcutil ...").ConfigureAwait(false))
            {
                // guard against bootstrapping recursion.
                if (this.Options.NoBootstrapping != true)
                {
                    Debug.Fail($"The NoBootstrapping property is not set, this would cause infinite bootstrapping recursion!");
                    return(null);
                }

                if (this.Options.Project != null && StringComparer.OrdinalIgnoreCase.Compare(this.Options.Project.FileName, SvcutilBootstrapper.ProjectName) == 0)
                {
                    Debug.Fail("Bootstrapping is enabled for the bootstrapper! This would cause an infinite bootstrapping recursion!");
                    return(null);
                }

                // When in Infrastructure mode (WCF CS) it is assumed the initial progress message is to be presented by the calling tool.
                ToolConsole.WriteLineIf(ToolConsole.ToolModeLevel != OperationalContext.Infrastructure, Resource.BootstrappingApplicationMsg);

                await GenerateProjectAsync(keepBootstrapperDir, logger, cancellationToken).ConfigureAwait(false);
                await GenerateProgramFileAsync(logger, cancellationToken).ConfigureAwait(false);

                var paramsFilePath = await GenerateParamsFileAsync(logger, cancellationToken).ConfigureAwait(false);

                await BuildBootstrapProjectAsync(logger, cancellationToken).ConfigureAwait(false);

                ToolConsole.WriteLineIf(ToolConsole.Verbosity >= Verbosity.Verbose, Resource.InvokingProjectMsg);
                result = await ProcessRunner.RunAsync("dotnet", $"run \"{paramsFilePath}\"", this.MSBuildProj.DirectoryPath, redirectOutput, logger, cancellationToken).ConfigureAwait(false);

                MarkupTelemetryHelper.TelemetryPostOperation(result.ExitCode == 0, "Invoke svcutil bootstrapper");
            }

            return(result);
        }