当我尝试在.NETStandard库的自定义构建目标中使用$(TargetFrameworkSDKToolsDirectory)
或$(SDKToolsPath)
等msbuild属性时,这些属性为空/未定义。然而,使用完全相同的.NET 4.6.2程序集构建目标可以正常工作。是否有.targets文件我需要手动包含.NETStandard或我还能缺少什么?
导入$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props
没有帮助。我正在使用Visual Studio 2017社区。 p>
* .csproj for .NETStandard lib:
<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 app:
<?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>
答案 0 :(得分:2)
对于.NET 4.6.2库,TargetFrameworkSDKToolsDirectory属性由Microsoft.NETFramework.CurrentVersion.props设置。
使用$(SDK35ToolsPath)或$(SDK40ToolsPath)进行设置。
SDK40ToolsPath属性在.NET标准库构建中可用,即使TargetFrameworkSDKToolsDirectory不是。