[英]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相关的信息。
You can leverage reflection's Assembly.ImageRuntimeVersion
property to grab it.您可以利用反射的
Assembly.ImageRuntimeVersion
属性来获取它。
Here's the documentation on it: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.imageruntimeversion?redirectedfrom=MSDN&view=net-6.0#System_Reflection_Assembly_ImageRuntimeVersion这是它的文档: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.imageruntimeversion?redirectedfrom=MSDN&view=net-6.0#System_Reflection_Assembly_ImageRuntimeVersion
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.