在nuget程序包中包含引用的项目DLL [.Net Core RC3 * .csproj文件]
我有一个包含两个项目的解决方案.第一个项目称为Library1,该项目引用了两个项目,称为Referencelibrary.我试图将用于ReferenceLibrary的DLL嵌入Library1的nuget包中,这样就不必发布2个单独的nuget包.通过将以下条目添加到我的csproj文件中,我已经能够将ReferenceLibrary的DLL嵌入到nuget包中:
I have a solution with two projects in it. First project is called Library1, which references project two called Referencelibrary. I am trying to embed the DLLs for ReferenceLibrary inside Library1's nuget package so that I don't have to publish 2 separate nuget packages. I've been able to embed ReferenceLibrary's DLL into the nuget package (so it seems) by adding the entries below into my csproj file:
<ItemGroup>
<ProjectReference Include="..\ReferenceLibrary\ReferenceLibrary.csproj">
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
<IncludeAssets>ReferenceLibrary.dll</IncludeAssets>
<IncludeAssets>ReferenceLibrary.pdp</IncludeAssets>
</ProjectReference>
</ItemGroup>
但是当我导入nuget包并尝试运行测试应用程序时,出现以下异常:
But when I import the nuget package and try to run my test app, I get the following exception:
我认为DLL已被嵌入,因为在将"IncludeAssets"添加到csproj之前,我无法导入nuget包,因为它试图引用ReferenceLibrary nuget包.但是在添加了这些条目之后,它允许我将其导入.但是现在它在运行时炸弹.任何帮助将不胜感激.谢谢!
I assumed that the DLLs had been embedded because prior to adding the "IncludeAssets" to the csproj, I wasn't able to import the nuget package because it was trying to reference the ReferenceLibrary nuget package. But after adding those entries, it allowed me to import it. But now it bombs at run-time. Any help would be greatly appreciated. Thanks!
;)
There is now a more up-to-date workaround described here. Simply add the TargetsForTfmSpecificBuildOutput
and Target
nodes to your .csproj
file as shown below.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
</Project>
可以在包目标中找到此扩展点的正式文档,这里.
Official documentation for this extension point in the pack target can be found here.