public string Resolve(string project, string configuration) { var finder = new MsBuildProjectFinder(_workingDirectory); var projectFile = finder.FindMsBuildProject(project); _reporter.Verbose(Resources.FormatMessage_Project_File_Path(projectFile)); configuration = !string.IsNullOrEmpty(configuration) ? configuration : DefaultConfig; var outputFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); try { var args = new[] { "msbuild", projectFile, "/nologo", "/t:_ExtractUserSecretsMetadata", // defined in SecretManager.targets "/p:_UserSecretsMetadataFile=" + outputFile, "/p:Configuration=" + configuration, "/p:CustomAfterMicrosoftCommonTargets=" + _targetsFile, "/p:CustomAfterMicrosoftCommonCrossTargetingTargets=" + _targetsFile, }; var psi = new ProcessStartInfo { FileName = DotNetMuxer.MuxerPathOrDefault(), Arguments = ArgumentEscaper.EscapeAndConcatenate(args), RedirectStandardOutput = true, RedirectStandardError = true }; #if DEBUG _reporter.Verbose($"Invoking '{psi.FileName} {psi.Arguments}'"); #endif var process = Process.Start(psi); process.WaitForExit(); if (process.ExitCode != 0) { _reporter.Verbose(process.StandardOutput.ReadToEnd()); _reporter.Verbose(process.StandardError.ReadToEnd()); throw new InvalidOperationException(Resources.FormatError_ProjectFailedToLoad(projectFile)); } var id = File.ReadAllText(outputFile)?.Trim(); if (string.IsNullOrEmpty(id)) { throw new InvalidOperationException(Resources.FormatError_ProjectMissingId(projectFile)); } return(id); } finally { TryDelete(outputFile); } }
public string Resolve(string project, string configuration) { var finder = new MsBuildProjectFinder(_workingDirectory); var projectFile = finder.FindMsBuildProject(project); _reporter.Verbose(Resources.FormatMessage_Project_File_Path(projectFile)); configuration = !string.IsNullOrEmpty(configuration) ? configuration : DefaultConfig; var outputFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); try { var psi = new ProcessStartInfo { FileName = DotNetMuxer.MuxerPathOrDefault(), RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, ArgumentList = { "msbuild", projectFile, "/nologo", "/t:_ExtractUserSecretsMetadata", // defined in SecretManager.targets "/p:_UserSecretsMetadataFile=" + outputFile, "/p:Configuration=" + configuration, "/p:CustomAfterMicrosoftCommonTargets=" + _targetsFile, "/p:CustomAfterMicrosoftCommonCrossTargetingTargets=" + _targetsFile, "-verbosity:detailed", } }; #if DEBUG _reporter.Verbose($"Invoking '{psi.FileName} {psi.Arguments}'"); #endif using var process = new Process() { StartInfo = psi, }; var outputBuilder = new StringBuilder(); var errorBuilder = new StringBuilder(); process.OutputDataReceived += (_, d) => { if (!string.IsNullOrEmpty(d.Data)) { outputBuilder.AppendLine(d.Data); } }; process.ErrorDataReceived += (_, d) => { if (!string.IsNullOrEmpty(d.Data)) { errorBuilder.AppendLine(d.Data); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); if (process.ExitCode != 0) { _reporter.Verbose(outputBuilder.ToString()); _reporter.Verbose(errorBuilder.ToString()); _reporter.Error($"Exit code: {process.ExitCode}"); throw new InvalidOperationException(Resources.FormatError_ProjectFailedToLoad(projectFile)); } if (!File.Exists(outputFile)) { throw new InvalidOperationException(Resources.FormatError_ProjectMissingId(projectFile)); } var id = File.ReadAllText(outputFile)?.Trim(); if (string.IsNullOrEmpty(id)) { throw new InvalidOperationException(Resources.FormatError_ProjectMissingId(projectFile)); } return(id); } finally { TryDelete(outputFile); } }
private static string ResolveProjectPath(string name, string path) { var finder = new MsBuildProjectFinder(path); return(finder.FindMsBuildProject(name)); }