Controlling Code Contract references in a .nuspec

六眼飞鱼酱① 提交于 2019-12-05 14:21:36

As Code Contracts are a separate and optional assembly, I'd recommend creating a new MyPackage.CodeContracts package which copies over the Code Contracts assembly to where you need it. This can be done using a simple PowerShell script (install.ps1 + uninstall.ps1) in a so called tools package.

This is a similar approach as for creating a MyPackage.Sample package for instance. Create the package using a convention based directory and target a .nuspec file instead. You'll have less issues and IMHO it's a nicer solution as well.

Following up -- newer NuGet versions seem to do what I had originally expected it to do and include the files without referencing them. No more need for custom installers.

This was an issue for me too. I have replicated it with the the Nuget Sample to: https://github.com/NuGet/Samples/issues/3

The package\metadata\references\group\reference node documentation: http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Explicit_Assembly_References_in_version_2.5_and_above

Someone else with the same issue: https://social.msdn.microsoft.com/Forums/en-US/fe7fad45-a474-4157-a4ee-3f94a2b1071f/nuget-package-dependency-reference-not-added-to-project?forum=visualstudiogeneral

Sample nuspec:

    <references>
        <reference file="My.ServiceBusEntities.dll" />
    </references>
</metadata>
<files>
    <file src="bin\Debug\My.ServiceBusEntities.dll" target="lib\net45\ServiceBusEntities.dll" />

NOTE: it is important to have the correct and matching "net45" framework folder in the file:target attribute to match the project target (i.e. framework 4.5).

Other wise have no framework specified and you will see references added to the Target Project. i.e.

<file src="bin\Debug\My.ServiceBusEntities.dll" target="lib\ServiceBusEntities.dll" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!