我想提供我创建的一个项目的NuGet包,但是我有一些“隐藏”依赖项的问题。
是否可以进行下列配置?
为了删除所有NuGet依赖项并隐藏B类型的依赖项,我尝试了以下操作:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<!-- PrivateAssets to remove NuGet depencies -->
<ItemGroup>
<ProjectReference Include="..\A.csproj" PrivateAssets="All" />
<ProjectReference Include="..\B.csproj" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)A.dll" />
<!-- B is hidden, so not included -->
</ItemGroup>
问题是,在运行时,内部NuGet代码会崩溃,因为它找不到依赖项B及其依赖项。(这很明显,因为DLL不存在。)
发布于 2018-06-06 18:43:05
只有当您对该包具有构建时依赖关系时,PrivateAssets="All"才有意义。
您想要的是控制B的资产流入项目本身。这意味着您想不允许消费者对B进行编码。
实现这一目标的方法是使用ExcludeAssets="compile"而不是PrivateAssets。
这样你就可以得到以下信息:
<ItemGroup>
<ProjectReference Include="..\A.csproj"/>
<ProjectReference Include="..\B.csproj" ExcludeAssets="compile" />
</ItemGroup>https://stackoverflow.com/questions/50724816
复制相似问题