PackageReference条件被忽略 [英] PackageReference condition is ignored

查看:311
本文介绍了PackageReference条件被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的VS 2017项目中,我引用了docfx.console包,我希望仅在满足特定条件时使用它.但是该软件包可用于所有构建.

In my VS 2017 project I reference docfx.console package and I want it to be used only when certain condition is met. But the package gets used for all builds.

这是我项目的一部分.我希望在配置为Installer/AnyCPU并且VS正在构建net40风格时使用docfx.console.

Here is a part of my project. I want docfx.console to be used when configuration is Installer/AnyCPU and VS is building net40 flavor.

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net40;netstandard1.3;netstandard2.0</TargetFrameworks>
    <!-- ... -->
    <Configurations>Debug;Release;Installer</Configurations>
  </PropertyGroup>

  <ItemGroup Condition=" '$(TargetFramework)'=='net40' ">
    <!-- ... -->
    <PackageReference Include="docfx.console" Version="2.30.0" Condition="'$(Configuration)|$(Platform)'=='Installer|AnyCPU'" />
  </ItemGroup>

    <!-- ... -->
</Project>

是否只有在net40的Installer构建中使用docfx.console的方法?

Is there a way to use docfx.console in Installer build for net40 only?

推荐答案

PackageReference条件被忽略

PackageReference condition is ignored

这是关于新样式csproj PackageReference与内容一起使用的已知问题 nuget包中的/Tools文件.

This is an known issue about the new style csproj PackageReference to work with content/Tools files in a nuget package.

在软件包docfx.console中,它看起来像docfx.console包含"content","build"和"tools",其中没有.NET代码,只是随机文件:

In the package docfx.console, it looks like docfx.console has "content", "build" and "tools" without .NET code in it, just random files:

在这种情况下,当我们安装此nuget软件包时,nuget不会执行任何操作.因此,它似乎已用于所有构建.那是因为:

In this case, when we install this nuget package, nuget does not do anything. So it seems gets used for all builds. That because:

与Packages.config一起使用的NuGet软件包,并不总是在 传递性NuGet环境(使用Project.json的项目或 PackageReferences).在传递性NuGet中工作的软件包 环境必须使用"contentFiles"而不是"content"-您可以 如果一个程序包想同时在两种环境下工作,则同时使用两者.还, install.ps1/uninstall.ps1在可传递的NuGet中不执行 环境-但是,init.ps1将在两个Packages.config中都可以工作 和传递环境.

NuGet packages that work with Packages.config, don't always work in transitive NuGet environments (projects using Project.json or PackageReferences). Packages that work in transitive NuGet environments must use "contentFiles" instead of "content" -- you can have both, if a package would like to work in both environments. Also, install.ps1/uninstall.ps1 doesn't execute in transitive NuGet environments -- however, init.ps1 will work in both Packages.config and transitive environments.

目前还没有完美的解决方案,因此问题4837 仍然开放.

At this moment, there is not a perfect solution, so the issue 4837 is still open.

要解决此问题,需要将NuGet docfx.console包更改为使用

To resolve this issue, the NuGet docfx.console package needs to be changed to use contentFiles and define targets and would typically reference a tool by using $(MSBuildThisFileDirectory)..\tools\MyTool.exe. If you put this PackageName.targets file into the a build directory, it will be automatically included into the project referencing the NuGet package.

希望这会有所帮助.

这篇关于PackageReference条件被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆