msbuild PackageReference.PrivateAssets =全部似乎不起作用 [英] msbuild PackageReference.PrivateAssets = All does not seem to work

查看:500
本文介绍了msbuild PackageReference.PrivateAssets =全部似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个引用NUnit3TestAdapter的测试项目.我不会将此引用复制到依赖此引用的项目中.

I have a test project which reference NUnit3TestAdapter. I do not this reference to be copied over to the projects that depend on this one.

我以为设置PrivateAssets = All可以做到,但显然我误会了它的工作原理,因为它没有理想的效果.

I thought setting PrivateAssets = All would do it, but apparently I misunderstand how it works, because it does not have the desired effect.

这是代码:

Rollup \ Rollup.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\UITests\UITests.csproj"/>
  </ItemGroup>

</Project>

UITests \ UITests.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NUnit3TestAdapter" Version="3.11.2">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Directory.Build.rsp

.\Rollup.sln /restore /v:m

运行msbuild后,所有内容均已构建,但是我可以看到NUnit3TestAdapter位于汇总文件夹的bin文件夹中.

After I run msbuild all is built, but I can see NUnit3TestAdapter is in the bin folder for Rollup.

我想念什么?

( https://github.com/Microsoft/msbuild/issues/3996)

推荐答案

PrivateAssets可以正常工作,但是NUnit测试适配器NuGet程序包将MSBuild目标添加到了版本中,该目标将一些dll文件作为内容项添加到了项目中,然后可以在构建过程中传递-与添加文本文件并设置其复制到输出目录"属性一样,效果相同.

PrivateAssets works as expected but the NUnit test adapter NuGet package adds an MSBuild target to the build that adds a few dll files as content items to the project, which then flow transitively through the build - this has the same effect as if you added a text file and set its "Copy to Output Directory" property.

NUnit3TestAdapter.props包含如下定义:

<Content Include="$(MSBuildThisFileDirectory)NUnit3.TestAdapter.dll">
  <Link>NUnit3.TestAdapter.dll</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <Visible>False</Visible>
</Content>

如果在Visual Studio解决方案资源管理器中单击显示所有文件",则应该看到这些文件.

You should see these files if you click the "Show All Files" in the Visual Studio solution explorer.

请注意,并不是真的应该打包或引用测试项目.它们应该是叶子项目.测试项目模板甚至包含<IsPackable>false</…>定义,并且XUnit的核心程序包还将其添加为导入的MSBuild文件.测试框架希望您将它们的抽象库而不是运行时程序集/测试适配器包用于共享测试或测试逻辑的项目.

Note that test projects aren't really supposed to be packaged or referenced. They should be leaf projects. The test project templates even contain an <IsPackable>false</…> definition and XUnit's core package also adds it as an imported MSBuild file. The test frameworks expect you to use their abstraction libraries and not runtime assemblies / test adapter packages for projects that share tests or test logic.

这篇关于msbuild PackageReference.PrivateAssets =全部似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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