Example #1
0
        private bool DotnetPack(CsprojInfo projectFile, DebugCommand cmd)
        {
            bool verbose    = cmd.Verbose;
            var  csprojPath = projectFile.Path;

            if (!Path.IsPathRooted(csprojPath))
            {
                throw new ArgumentException($"{nameof(csprojPath)} must be rooted");
            }

            // dotnet pack --include-symbols --include-source -c Debug
            // see: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack
            var name = "dotnet";
            //var args = $"pack '{csprojPath}' --include-symbols --include-source -c Debug";
            var args = $"pack --include-symbols --include-source -c Debug {cmd.PackArguments}";

            _logger.Info($"creating {projectFile.NugetPackageName}");

            var output = ExecuteProcess(name, args, csprojPath, verbose);


            const string fallbackTraceMessage =
                "error : If you are building projects that require targets from full MSBuild or MSBuildFrameworkToolsPath, you need to use desktop msbuild ('msbuild.exe') instead of 'dotnet build' or 'dotnet msbuild'";
            var fallbackToMsBuildRequired = output.Output.Any(l => l.Contains(fallbackTraceMessage));

            if (verbose)
            {
                foreach (var line in output.Output)
                {
                    _logger.Debug(line);
                }
                _logger.Debug($"dotnet pack returned {output.ExitCode}");
            }

            if (fallbackToMsBuildRequired)
            {
                if (verbose)
                {
                    _logger.Debug("falling back to full MSBuild as advanced targets are required...");
                }

                return(MsBuildPack(projectFile, verbose));
            }

            // only iif dotnet pack returns 0, everything is fine
            return(output.ExitCode == 0);
        }
Example #2
0
        private bool MsBuildPack(CsprojInfo projectFile, bool verbose)
        {
            var workingDir = Path.GetDirectoryName(projectFile.Path);

            // call vswhere - see: https://github.com/Microsoft/vswhere
            var vswhereEnv  = @"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe";
            var vswherePath = Environment.ExpandEnvironmentVariables(vswhereEnv);

            var o = ExecuteProcess(vswherePath,
                                   @"-latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe",
                                   workingDir, verbose);

            var msBuildPath = o.ExitCode == 0 ? o.Output.Single() : null;

            if (verbose && o.ExitCode == 0)
            {
                _logger.Debug($"found msbuild at '{msBuildPath}'");
            }
            if (o.ExitCode != 0)
            {
                _logger.Error("Could not find msbuild.exe. Please ensure that you have Visual Studio 2017 or higher installed on your machine!");
                return(false);
            }

            var o2 = ExecuteProcess(msBuildPath,
                                    $"\"{projectFile.Path}\" /t:pack /v:m /p:Configuration=Debug /p:IncludeSymbols=true",
                                    workingDir, verbose);

            if (verbose)
            {
                foreach (var l in o2.Output)
                {
                    _logger.Verbose(l);
                }
            }

            // only iif msbuild pack returns 0, everything is fine
            return(o2.ExitCode == 0);
        }