如何使用Microsoft.Codeanalysis(或类似)获取项目的目标框架/s? 我构建了一个.NET工具,该工具需要查询诸如目标框架之类的项目属性。我的第一个想法是Microsoft.ecodeanalysis。 使用microsoft.build.locator; 使用Microsoft.scodeanalysis.

问题描述 投票:0回答:2
pr

实例中看到很多信息,但是我没有找到与tfms.

的任何相关信息。
	

您可以利用反思的财产来抓住它。 the IT的文档:

Https://learn.microsoft.com/en-us/dotnet/api/system.reflection.sembly.imageruntimeversion?rediredectime?rediredection from = msdn&view = net-6.0#
    

c# .net msbuild microsoft.codeanalysis
2个回答
0
投票
遵循Microsoft

Exactly

提供的指南。是的,您需要
Assembly.ImageRuntimeVersion

;是的,您需要在此处解释的

季度分配代码。 在您的csproj(替代最新包装版本):

Microsoft.Build.Locator

0
投票

<ItemGroup> <PackageReference Include="Microsoft.Build" Version="17.12.6" ExcludeAssets="runtime" /> <PackageReference Include="Microsoft.Build.Locator" Version="1.7.8" /> <PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.12.6" ExcludeAssets="runtime" /> </ItemGroup> Program.cs

注意,如果您使用的是可能影响项目文件属性的最终计算值的另一个文件,则该程序将正确考虑到这一点!例如,我在Testign时提供的CSPROJ没有定义上述代码时,因为它从根级
using Microsoft.Build.Locator; using Microsoft.CodeAnalysis.MSBuild; public static class Program { public static void Main() { MSBuildLocator.RegisterDefaults(); PrintTfm(); } static void PrintTfm() { Project csproj = new( @"E:\Repos\SuperJMN\DotNet-Ssh-Deployer\NetCoreSsh\DotNetSsh.csproj"); var tfmProperty = csproj.GetProperty("TargetFramework"); // prints something like "net8.0" Console.WriteLine(tfmProperty.EvaluatedValue); } } Directory.Build.props

TargetFramework

Directory.Build.props
--输出的TFM继承了该值,而输出的TFM是(正确的)后一个文件中定义的值。

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.