NuGet 3.3+:内容文件未添加到项目 [英] NuGet 3.3+: contentFiles not added to project

查看:70
本文介绍了NuGet 3.3+:内容文件未添加到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了关于 NuGet 3.3+ 的新 contentFiles 元素的所有内容后,我仍然无法让它在我的包中工作.我有一个同时面向 net46uap10.0 的包,并且为项目类型和平台选择了正确的 DLL,按预期工作.但我还想在包安装时向项目添加两个文件,一个用于所有项目和平台的 CSV 文件,以及一个用于 C# 或 VB.Net 的代码文件(带有 buildAction="Compile").这是我最新的 .nuspec 文件的删节版:

After reading everything I could find about the new contentFiles element of NuGet 3.3+, I still can't manage to make it work in my package. I've got a package that targets both net46 and uap10.0, and the selection of the right DLLs for the project type and platform work as expected. But I would also like to add two files to the project on package installation, one CSV file for all projects and platforms, and one code file for either C# or VB.Net (with buildAction="Compile"). Here's the abridged version of my latest .nuspec file:

<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata minClientVersion="3.3.0">
    ...
    <contentFiles>
      <files include="any\any\ErrorCodes.csv" buildAction="None" copyToOutput="false" />
      <files include="cs\any\Errors.cs.pp" buildAction="Compile" />
      <files include="vb\any\Errors.vb" buildAction="Compile" />
    </contentFiles>
  </metadata>
  <files>
    <file src="contentFiles\any\any\ErrorCodes.csv" target="contentFiles\any\any\" />
    <file src="contentFiles\cs\any\Errors.cs.pp" target="contentFiles\cs\any\" />
    <file src="contentFiles\vb\any\Errors.vb" target="contentFiles\vb\any\" />
    ...
  </files>
</package>

创建的包没有错误,它确实包含具有指定目录结构的 contentFiles 文件夹中的三个文件.

The package is created without errors, and it does contain the three files in the contentFiles folder with the specified directory structure.

但是当我安装包时 - 我尝试使用通用应用程序(C# 和 VB)和 .NET 4.6 控制台应用程序我修改为使用 project.json 文件 - 参考添加到 DLL 中,但内容文件既没有添加到项目结构中,也没有复制到项目目录中.

But when I install the package - I tried it with with both an Universal App (C# and VB) and a .NET 4.6 console app I modified to use a project.json file - the reference to the DLL is added, but the content files are neither added to the project structure, nor copied into the project directory.

感谢您的任何意见!

推荐答案

好的,我发现 contentFiles 确实在工作,但不是我预期的那样.对于找不到他/她的内容文件的每个人的简短说明:

OK, I found that the contentFiles are actually working, but not in the way I expected it to. A short description for everybody who couldn't find his/her contentFiles:

  • NuGet 3.3+ contentFiles 添加到项目结构中.您不会在 Visual Studio 中看到它们.
  • 相反,文件被提取到项目的 obj 文件夹中的文件夹中,并被引用(如果文件是代码).您甚至会看到 IntelliSense 中可用的 contentFiles 代码文件中的类或方法.在我的例子中,Errors 类是可以访问的,尽管它在项目的任何地方都不可见.
  • 提取文件的路径具有以下架构:\obj\\NuGet\\\\
  • NuGet 3.3+ contentFiles are not added to the project structure. You will not see them in Visual Studio.
  • Instead, the files are extracted into a folder in the project's obj folder, and referenced (if the file is code). You will even see the classes or methods in your contentFiles code files available in IntelliSense. In my case, the Errors class was accessible, although it wasn't visible anywhere in the project.
  • The path of the extracted files has the following schema: \obj\<Debug or Release>\NuGet\<some GUID>\<NuGet package name>\<version>\

我不确定我是否喜欢这种新机制.来自一些我在 Visual Studio 中看不到的不可见源的代码(通过 NuGet 提供的库在参考中可见,它通过 contentFiles 提供的任何代码都看不到)有时可能会带来问题.实际上,当我在 Visual Studio 中遇到歧义错误时,我发现 contentFiles 机制正在起作用,因为 NuGet 包中的不可见"Errors.cs 与我手动添加到项目中的可见"Errors.cs 发生冲突.

I'm not sure if I like this new mechanism. Code coming from some invisible source I cannot see in Visual Studio (a library shipped via NuGet is visible in References, any code it brings via contentFiles is not) may pose problems at times. I actually discovered that the contentFiles mechanism is working when I got an ambiguity error in Visual Studio because the "invisible" Errors.cs from the NuGet package collided with the "visible" Errors.cs I had added to the project manually.

这篇关于NuGet 3.3+:内容文件未添加到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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