简体   繁体   English

仅限内容的Nuget程序包无法还原内容

[英]Content-only Nuget package fails to restore content

I've created a content-only Nuget package that adds a text file to the project it's installed into. 我创建了一个仅限内容的Nuget包,它将文本文件添加到它安装的项目中。 I checked in the project without the text file as I want it to be restored during nuget restore . 我在没有文本文件的情况下检查了项目,因为我希望在nuget restore期间nuget restore All is well until the CI machine tries to restore the package. 一切都很好,直到CI机器尝试恢复包。 The restore succeeds but the text file is not added. 还原成功但未添加文本文件。 Apparently, nuget thinks that the text file already exists since there is a reference to it in the project file. 显然,nuget认为文本文件已经存在,因为项目文件中有对它的引用。

How do I get nuget to restore the text file? 如何让nuget恢复文本文件?

Essentially, the behaviour I want is the same as with DLL files: when a package is installed, references to DLLs are added to the project; 本质上,我想要的行为与DLL文件相同:当安装包时,对DLL的引用被添加到项目中; when the package is restored, DLLs are restored to satisfy the references in the project file. 当包恢复时,将恢复DLL以满足项目文件中的引用。 I want the same behaviour but for text files. 我想要相同的行为,但对于文本文件。 Is this possible? 这可能吗?

What I ended up doing was putting the text file into the top-level folder like this (a snippet from my .nuspec): 我最终做的是将文本文件放入顶级文件夹(这是我的.nuspec的一个片段):

    </metadata>
    <files>
        <file src="dictionary.txt" target="dictionary.txt" />
    </files>
</package>

So when the package is installed, the file is put into /packages/MyPackage.0.0.6 and referenced from the .csproj like so: 因此,在安装软件包时,文件将放入/packages/MyPackage.0.0.6并从.csproj中引用,如下所示:

<ItemGroup>
  <EmbeddedResource Include="$(SolutionDir)packages\MyPackage.0.0.6\dictionary.txt" />
</ItemGroup>

Then the file is read from .cs like this: 然后从.cs读取文件,如下所示:

var stream = Assembly.GetExecutingAssembly()
             .GetManifestResourceStream(GetType(), "dictionary.txt");

This got me the desired behaviour: when the package is restored, the file is restored and put exactly where the reference is pointing to. 这让我得到了理想的行为:当包恢复时,文件将被恢复并准确放置在引用所指向的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM