【问题标题】:MSBuild properties empty for .NETStandard lib project.NETStandard lib 项目的 MSBuild 属性为空
【发布时间】:2017-03-16 00:11:17
【问题描述】:

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

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

*.csproj 用于 .NETStandard 库:

<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 用于 .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>

【问题讨论】:

  • .NETStandard 项目应该与 iOS、Android、Linux 等平台目标兼容。想用 Windows SDK 做任何事情都是没有意义的。避免 XY 问题。
  • 特别想使用 ildasm/ilasm。那么还有另一种使用它们的方法吗?该功能应该在其他平台上可用,不是吗?另外,“避免 XY 问题”是什么意思?
  • 好的,我现在知道什么是 XY 问题 (meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。多么难以描述的名字……我应该删除这个问题还是留给其他尝试与我相同(愚蠢)方法的人?

标签: c# msbuild .net-standard


【解决方案1】:

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

使用 $(SDK35ToolsPath) 或 $(SDK40ToolsPath) 设置。

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

【讨论】:

  • 谢谢,这正是我需要的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多