我正在使用代码契约为我的项目生成附属程序集。 基本上它为项目的MyAssembly.dll创建了MyAssembly.Contracts.dll。 这应该放在你的程序集旁边但不被任何应用程序引用 - 它只由合同工具使用。
我正在尝试将其包含在我的nuget包中,但是当我将该包安装到另一个应用程序中时,Contracts程序集将作为参考包含在内,从而产生问题。
根据.nuspec引用 ,这应该像添加references元素一样简单,但它似乎被忽略了。 我现在的理论是,这是因为我使用.csproj来替换令牌,它正在读取.csproj而不是.nuspec的引用。
有没有人这样做过? 有任何想法吗?
以下是我的.nuspec的相关部分:
<?xml version="1.0"?> <package> <metadata> <references> <reference file="MyAssembly.dll"/> </references> </metadata> <files> <file src="bin\Release\CodeContracts\*.dll" target="lib\net45"/> </files> </package>I'm using Code Contracts to generate satellite assemblies for my project. Basically it creates a MyAssembly.Contracts.dll for the project's MyAssembly.dll. This is supposed to be put beside your assembly but not referenced by any app -- it's used only by the contracts tools.
I'm trying to include this in my nuget package, but when I then install that package into another app, the Contracts assembly is included as a reference which creates problems.
According to the .nuspec reference, this should be as simple as adding a references element, but it seems to be ignored. My current theory is that this is because I'm using a .csproj for replacement tokens, and it's reading references from the .csproj and not the .nuspec.
Has anyone done this before? Any ideas?
Here are the relevant parts of my .nuspec:
<?xml version="1.0"?> <package> <metadata> <references> <reference file="MyAssembly.dll"/> </references> </metadata> <files> <file src="bin\Release\CodeContracts\*.dll" target="lib\net45"/> </files> </package>最满意答案
由于Code Contracts是一个单独的可选程序集, 我建议创建一个新的MyPackage.CodeContracts包 ,它将Code Contracts程序集复制到您需要的位置。 这可以使用所谓的工具包中的简单PowerShell脚本(install.ps1 + uninstall.ps1)来完成。
这与创建MyPackage.Sample包的方法类似。 使用基于约定的目录创建包,并以.nuspec文件为目标。 你会遇到更少的问题,恕我直言,这也是一个更好的解决方案。
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.
更多推荐
nuspec,Contracts,dll,电脑培训,计算机培训,IT培训"/> <meta name="descript
发布评论