0

我正在构建一个 .NET 工具,该工具需要查询 Target Framework/s 等项目属性。我的第一个想法是 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");
    }
}

我已经加载了一个项目,我可以在pr实例中看到很多信息,但是我没有找到任何与 TFM 相关的信息。

4

1 回答 1

0

您可以利用反射的Assembly.ImageRuntimeVersion属性来获取它。

这是关于它的文档:https ://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.imageruntimeversion?redirectedfrom=MSDN&view=net-6.0#System_Reflection_Assembly_ImageRuntimeVersion

于 2022-01-16T22:22:08.277 回答