private static async Task <IReadOnlyList <ProjectOutputInfo> > GetOutputInfoAsync(Project project) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var alternatives = new Dictionary <string, ProjectOutputInfo>(); var unconfigured = (project as IVsBrowseObjectContext)?.UnconfiguredProject; if (unconfigured != null) { foreach (var loaded in unconfigured.LoadedConfiguredProjects) { var task = loaded.GetType() .GetProperty("MSBuildProject", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .GetMethod.Invoke(loaded, null) as Task <Microsoft.Build.Evaluation.Project>; var msbuildProperties = (await task).AllEvaluatedProperties; var targetPath = GetMsBuildProperty(msbuildProperties, "TargetPath"); if (!string.IsNullOrWhiteSpace(targetPath)) { var hostAppNetCore = GetMsBuildProperty(msbuildProperties, "AvaloniaPreviewerNetCoreToolPath"); var hostAppNetFx = GetMsBuildProperty(msbuildProperties, "AvaloniaPreviewerNetFullToolPath"); var tf = GetFrameworkInfo(loaded, msbuildProperties, "TargetFramework"); var tfi = GetFrameworkInfo(loaded, msbuildProperties, "TargetFrameworkIdentifier"); var hostApp = FrameworkInfoUtils.IsNetFramework(tfi) ? hostAppNetFx : hostAppNetCore; alternatives[tf] = new ProjectOutputInfo(targetPath, tf, tfi, hostApp); } } } return(alternatives.Values.ToList()); }
private static async Task <IReadOnlyList <ProjectOutputInfo> > GetOutputInfoAsync(Project project) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var alternatives = new Dictionary <string, ProjectOutputInfo>(); var unconfigured = (project as IVsBrowseObjectContext)?.UnconfiguredProject; if (unconfigured != null) { foreach (var loaded in unconfigured.LoadedConfiguredProjects) { var task = loaded.GetType() .GetProperty("MSBuildProject", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .GetMethod.Invoke(loaded, null) as Task <Microsoft.Build.Evaluation.Project>; var msbuildProperties = (await task).AllEvaluatedProperties; var targetPath = msbuildProperties.FirstOrDefault(p => p.Name == "TargetPath")?.EvaluatedValue; var hostAppNetCore = msbuildProperties.FirstOrDefault(x => x.Name == "AvaloniaPreviewerNetCoreToolPath")?.EvaluatedValue; var hostAppNetFx = msbuildProperties.FirstOrDefault(x => x.Name == "AvaloniaPreviewerNetFullToolPath")?.EvaluatedValue; if (!string.IsNullOrWhiteSpace(targetPath)) { if (!loaded.ProjectConfiguration.Dimensions.TryGetValue("TargetFramework", out var targetFw)) { targetFw = (await task).AllEvaluatedProperties.FirstOrDefault(p => p.Name == "TargetFramework") ?.EvaluatedValue ?? "unknown"; } var outputInfo = new ProjectOutputInfo { TargetAssembly = targetPath, TargetFramework = targetFw == "classic" ? "net40" : targetFw, HostApp = hostAppNetCore, }; outputInfo.HostApp = outputInfo.IsFullDotNet ? hostAppNetFx : hostAppNetCore; alternatives[targetFw] = outputInfo; } } } return(alternatives.Values.ToList()); }
private static async Task<IReadOnlyList<ProjectOutputInfo>> GetOutputInfoAsync(Project project) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var alternatives = new Dictionary<string, string>(); var unconfigured = (project as IVsBrowseObjectContext)?.UnconfiguredProject; if (unconfigured != null) { foreach (var loaded in unconfigured.LoadedConfiguredProjects) { var task = loaded.GetType() .GetProperty("MSBuildProject", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .GetMethod.Invoke(loaded, null) as Task<Microsoft.Build.Evaluation.Project>; var targetPath = (await task).AllEvaluatedProperties.FirstOrDefault(p => p.Name == "TargetPath")?.EvaluatedValue; if (!string.IsNullOrWhiteSpace(targetPath)) { if (!loaded.ProjectConfiguration.Dimensions.TryGetValue("TargetFramework", out var targetFw)) targetFw = (await task).AllEvaluatedProperties.FirstOrDefault(p => p.Name == "TargetFramework") ?.EvaluatedValue ?? "unknown"; alternatives[targetFw] = targetPath; } } } string fullPath = TryGetProperty(project?.Properties, "FullPath"); string outputPath = project?.ConfigurationManager?.ActiveConfiguration?.Properties?.Item("OutputPath")?.Value?.ToString(); if (fullPath != null && outputPath != null) { string outputDir = Path.Combine(fullPath, outputPath); string outputFileName = project.Properties.Item("OutputFileName").Value.ToString(); if (!string.IsNullOrWhiteSpace(outputFileName)) { var fw = "net40"; var tfm = TryGetProperty(project.Properties, "TargetFrameworkMoniker"); const string tfmPrefix = ".netframework,version=v"; if (tfm != null && tfm.ToLowerInvariant().StartsWith(tfmPrefix)) fw = "net" + tfm.Substring(tfmPrefix.Length).Replace(".", ""); string assemblyPath = Path.Combine(outputDir, outputFileName); alternatives[fw] = assemblyPath; } } var outputType = TryGetProperty(project?.Properties, "OutputType") ?? TryGetProperty(project?.ConfigurationManager?.ActiveConfiguration?.Properties, "OutputType"); var outputTypeIsExecutable = outputType == "0" || outputType == "1" || outputType?.ToLowerInvariant() == "exe" || outputType?.ToLowerInvariant() == "winexe"; var lst = new List<ProjectOutputInfo>(); foreach (var alternative in alternatives.OrderByDescending(x => x.Key == "classic" ? 10 : s_desktopFrameworkRegex.IsMatch(x.Key) ? 9 : x.Key.StartsWith("netcoreapp") ? 8 : x.Key.StartsWith("netstandard") ? 7 : 0)) { var nfo = new ProjectOutputInfo { TargetAssembly = alternative.Value, OutputTypeIsExecutable = outputTypeIsExecutable, TargetFramework = alternative.Key == "classic" ? "net40" : alternative.Key }; nfo.IsNetCore = nfo.TargetFramework.StartsWith("netcoreapp"); nfo.IsNetStandard = nfo.TargetFramework.StartsWith("netstandard"); nfo.IsFullDotNet = s_desktopFrameworkRegex.IsMatch(nfo.TargetFramework); lst.Add(nfo); } return lst; }
static List <ProjectOutputInfo> GetProjectOutputInfoInternal(this Project vsProject) { var alternatives = new Dictionary <string, string>(); var ucproject = GetUnconfiguredProject(vsProject); if (ucproject != null) { foreach (var loaded in ucproject.LoadedConfiguredProjects) { var task = loaded.GetType() .GetProperty("MSBuildProject", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .GetMethod.Invoke(loaded, null) as Task <Microsoft.Build.Evaluation.Project>; if (task?.IsCompleted != true) { continue; } var targetPath = task.Result.AllEvaluatedProperties.FirstOrDefault(p => p.Name == "TargetPath")?.EvaluatedValue; if (!string.IsNullOrWhiteSpace(targetPath)) { if (!loaded.ProjectConfiguration.Dimensions.TryGetValue("TargetFramework", out var targetFw)) { targetFw = task.Result.AllEvaluatedProperties.FirstOrDefault(p => p.Name == "TargetFramework") ?.EvaluatedValue ?? "unknown"; } alternatives[targetFw] = targetPath; } } } string fullPath = TryGetProperty(vsProject?.Properties, "FullPath"); string outputPath = vsProject?.ConfigurationManager?.ActiveConfiguration?.Properties?.Item("OutputPath")?.Value?.ToString(); if (fullPath != null && outputPath != null) { string outputDir = Path.Combine(fullPath, outputPath); /* * var dic = new Dictionary<string, string>(); * foreach(Property prop in vsProject.Properties) * { * try * { * dic[prop.Name] = prop.Value?.ToString(); * } * catch * { * * } * }*/ string outputFileName = vsProject.Properties.Item("OutputFileName").Value.ToString(); if (!string.IsNullOrWhiteSpace(outputFileName)) { var fw = "net40"; var tfm = TryGetProperty(vsProject.Properties, "TargetFrameworkMoniker"); const string tfmPrefix = ".netframework,version=v"; if (tfm != null && tfm.ToLowerInvariant().StartsWith(tfmPrefix)) { fw = "net" + tfm.Substring(tfmPrefix.Length).Replace(".", ""); } string assemblyPath = Path.Combine(outputDir, outputFileName); alternatives[fw] = assemblyPath; } } var outputType = TryGetProperty(vsProject?.Properties, "OutputType") ?? TryGetProperty(vsProject?.ConfigurationManager?.ActiveConfiguration?.Properties, "OutputType"); var outputTypeIsExecutable = outputType == "0" || outputType == "1" || outputType?.ToLowerInvariant() == "exe" || outputType?.ToLowerInvariant() == "winexe"; var lst = new List <ProjectOutputInfo>(); foreach (var alternative in alternatives.OrderByDescending(x => x.Key == "classic" ? 10 : DesktopFrameworkRegex.IsMatch(x.Key) ? 9 : x.Key.StartsWith("netcoreapp") ? 8 : x.Key.StartsWith("netstandard") ? 7 : 0)) { var nfo = new ProjectOutputInfo { TargetAssembly = alternative.Value, OutputTypeIsExecutable = outputTypeIsExecutable, TargetFramework = alternative.Key == "classic" ? "net40" : alternative.Key }; nfo.IsNetCore = nfo.TargetFramework.StartsWith("netcoreapp"); nfo.IsFullDotNet = DesktopFrameworkRegex.IsMatch(nfo.TargetFramework); lst.Add(nfo); } return(lst); }