简体   繁体   English

如何使用 Microsoft.CodeAnalysis(或类似)获取项目(.csproj)的目标框架?

[英]How to get the Target Framework/s of a project (.csproj) using Microsoft.CodeAnalysis (or similar)?

I'm building a .NET tool that needs to query project properties like Target Framework/s.我正在构建一个 .NET 工具,该工具需要查询 Target Framework/s 等项目属性。 My first thought has been Microsoft.CodeAnalysis.我的第一个想法是 Microsoft.CodeAnalysis。

using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis.MSBuild;

public static class Program
{
    public static async Task Main()
    {
        MSBuildLocator.RegisterDefaults(); 
        using var workspace = MSBuildWorkspace.Create();
        var pr = await workspace.OpenProjectAsync("E:\\Repos\\SuperJMN\\DotNet-Ssh-Deployer\\NetCoreSsh\\DotNetSsh.csproj");
    }
}

I've loaded a project, and I can see a lot of information in the pr instance, but I haven't found anything related to the TFMs.我已经加载了一个项目,可以在pr实例中看到很多信息,但是我没有找到任何与TFM相关的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 memory 中编译并使用 Microsoft.CodeAnalysis 获取程序集 - How to compile in memory and get assembly using Microsoft.CodeAnalysis 使用 Microsoft.CodeAnalysis,如何获取 Type 类型的 Attribute 属性的值? - Using Microsoft.CodeAnalysis, how do I get the value of an Attribute property that is of type Type? 使用Roslyn(Microsoft.CodeAnalysis)查询WebSite项目的信息 - Using Roslyn (Microsoft.CodeAnalysis) to query information of WebSite projects Microsoft.CodeAnalysis.FxCopAnalyzers 和 Microsoft.CodeAnalysis 之间有什么区别? - What's the difference between Microsoft.CodeAnalysis.FxCopAnalyzers and Microsoft.CodeAnalysis? 无法加载文件或程序集 Microsoft.CodeAnalysis - Could not load file or assembly Microsoft.CodeAnalysis 在Roslyn与Microsoft.CodeAnalysis中添加MetadataReference - Adding MetadataReference in Roslyn Vs Microsoft.CodeAnalysis Microsoft.CodeAnalysis无法加载文件 - Microsoft.CodeAnalysis failed to load file 在哪里阅读Microsoft.CodeAnalysis的文档? - Where to read docs for Microsoft.CodeAnalysis? C#vS2017项目未生成:无法加载文件或程序集Microsoft.CodeAnalysis - C# vS2017 project not building: Could not load file or assembly Microsoft.CodeAnalysis 在Roslyn的新版本(Microsoft.CodeAnalysis)中,`Solution.LoadStandAloneProject`发生了什么? - What happened to `Solution.LoadStandAloneProject` in Roslyn's new version (Microsoft.CodeAnalysis)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM