控制在.nuspec code合同参考 [英] Controlling Code Contract references in a .nuspec

查看:82
本文介绍了控制在.nuspec code合同参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用code合同生成附属程序集为我的项目。基本上,它会创建一个MyAssembly.Contracts.dll项目的MyAssembly.dll程序。这应该是你的程序集旁边放,但不被任何应用程序所引用 - 这只是所用的工具合约

我想包括这在我的NuGet包,但是当我然后安装包到另一个应用程序,合同组件包括在其产生问题的参考。

按照 .nuspec参考,这应该是简单添加了一个引用元素,但它似乎被忽略。我目前的理论是,这是因为我使用的.csproj更换标记,而且它从.csproj的阅读参考,而不是.nuspec。

有没有人这样做过?任何想法?

下面是我.nuspec的相关部分:

 < XML版本=1.0&GT?;
<包装>
  <元>
     <参考>
          <参考文件=MyAssembly.dll程序/>
     < /引用>
  < /元>
  <文件>
     <文件SRC =BIN \发布\ codeContracts \ *。dll的。TARGET =lib目录\ net45/>
  < /文件>
< /包>
 

解决方案

由于code合同是独立的和组装我建议创建一个新的MyPackage的。codeContracts包这在code装配合同副本,在你需要它。这可以在所谓的工具包

使用一个简单的PowerShell脚本(install.ps1 + uninstall.ps1)完成

这是一个类似的方法作为创建MyPackage.Sample包实例。创建使用约定基于目录的包,并针对一个.nuspec文件来代替。您将有较少的问题,恕我直言,这是一个更好的解决方案,以及。

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>

解决方案

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 code合同参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆