.NETStandard lib 项目的 MSBuild 属性为空

MSBuild properties empty for .NETStandard lib project

当我尝试在 .NETStandard 库的自定义构建目标中使用 $(TargetFrameworkSDKToolsDirectory)$(SDKToolsPath) 等 msbuild 属性时,这些属性是 empty/not 定义的。但是,对 .NET 4.6.2 程序集使用完全相同的构建目标可以正常工作。是否有我需要为 .NETStandard 手动包含的 .targets 文件或我可能遗漏的其他文件?

导入 $(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props 没有帮助。我正在使用 Visual Studio 2017 社区。

*.NETStandard 库的.csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard1.4</TargetFramework>
        <RootNamespace>MyNamespace</RootNamespace>
        <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
    </PropertyGroup>
    <!--
    ItemGroups for files and references
    -->
    <Target Name="PropsTest" BeforeTargets="CoreCompile">
        <!-- Prints: "Path: " -->
        <Message Text="Path: $(TargetFrameworkSDKToolsDirectory)" Importance="high" />
    </Target>
</Project>

*.csproj for .NET 4.6.2 应用程序:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{73E77BB7-D3F9-4797-B62D-24666D1132EF}</ProjectGuid>
        <OutputType>Exe</OutputType>
        <RootNamespace>SamplesConsole</RootNamespace>
        <AssemblyName>SamplesConsole</AssemblyName>
        <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <TargetFrameworkProfile />
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
    </PropertyGroup>
    <!--
    ItemGroups for files and references
    -->
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    <Target Name="PropsTest" BeforeTargets="CoreCompile">
        <!-- Prints: "Path: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\" -->
        <Message Text="Path: $(TargetFrameworkSDKToolsDirectory)" Importance="high" />
    </Target>
</Project>

对于 .NET 4.6.2 库,TargetFrameworkSDKToolsDirectory 属性 由 Microsoft.NETFramework.CurrentVersion.props 设置。

它设置为 $(SDK35ToolsPath) 或 $(SDK40ToolsPath)。

SDK40ToolsPath 属性 在 .NET 标准库构建中可用,即使 TargetFrameworkSDKToolsDirectory 不可用。