pr
实例中看到很多信息,但是我没有找到与tfms.
的任何相关信息。您可以利用反思的财产来抓住它。 the IT的文档:
Https://learn.microsoft.com/en-us/dotnet/api/system.reflection.sembly.imageruntimeversion?rediredectime?rediredection from = msdn&view = net-6.0#
Exactly
提供的指南。是的,您需要
Assembly.ImageRuntimeVersion
;是的,您需要在此处解释的季度分配代码。 在您的csproj(替代最新包装版本):
Microsoft.Build.Locator
<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是(正确的)后一个文件中定义的值。