控制.nuspec中的代码合同引用(Controlling Code Contract references in a .nuspec)

编程入门 行业动态 更新时间:2024-10-25 16:26:47
控制.nuspec中的代码合同引用(Controlling Code Contract references in a .nuspec)

我正在使用代码契约为我的项目生成附属程序集。 基本上它为项目的MyAssembly.dll创建了MyAssembly.Contracts.dll。 这应该放在你的程序集旁边但不被任何应用程序引用 - 它只由合同工具使用。

我正在尝试将其包含在我的nuget包中,但是当我将该包安装到另一个应用程序中时,Contracts程序集将作为参考包含在内,从而产生问题。

根据.nu​​spec引用 ,这应该像添加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

本文发布于:2023-08-07 21:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:合同   代码   nuspec   Controlling   references

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!