我有一些c#书中的。nupkg文件。我如何安装它们?
当前回答
菜单工具→选项→包管理器
给出名称和文件夹位置。单击OK。将您的NuGet包文件放在该文件夹中。
转到解决方案资源管理器中的项目,右键单击并选择“管理NuGet包”。选择新的包源。
这里是文档。
其他回答
用于Visual Studio 2017及其新的.csproj格式
您不能再仅仅使用Install-Package来指向本地文件。(这可能是因为PackageReference元素不支持文件路径;它只允许你指定包的Id。)
首先必须告诉Visual Studio包的位置,然后才能将其添加到项目中。大多数人做的是进入NuGet包管理器并添加本地文件夹作为源(菜单工具→选项→NuGet包管理器→包源)。但这意味着你的依赖项的位置不会与你的代码库的其他部分一起提交(到版本控制)。
使用相对路径的本地NuGet包
这将添加一个只适用于特定解决方案的包源,您可以使用相对路径。
你需要创造一个楔子。配置文件与您的.sln文件在同一目录下。将文件配置为所需的包源。当您下次在Visual Studio 2017中打开解决方案时,来自这些源文件夹的任何.nupkg文件都将可用。(您将在Package Manager中看到列出的源代码,当您管理项目的包时,您将在“Browse”选项卡上找到包。)
这里有一个例子。配置让你开始:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyLocalSharedSource" value="..\..\..\some\folder" />
</packageSources>
</configuration>
基本信息
My use case for this functionality is that I have multiple instances of a single code repository on my machine. There's a shared library within the codebase that's published/deployed as a .nupkg file. This approach allows the various dependent solutions throughout our codebase to use the package within the same repository instance. Also, someone with a fresh install of Visual Studio 2017 can just checkout the code wherever they want, and the dependent solutions will successfully restore and build.
您还可以使用包管理器控制台并通过在-Source参数中指定包含包文件的目录的路径来调用安装包cmdlet:
Install-Package SomePackage -Source C:\PathToThePackageDir\
如果你有一个.nupkg文件,只需要.dll文件,你所要做的就是将扩展名更改为.zip,然后找到lib目录。
Add the files to a folder called LocalPackages next to you solution (it doesn't have to be called that, but adjust the xml in the following step accordingly) Create a file called NuGet.config next to your solution file with the following contents <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="LocalPackages" value="./LocalPackages" /> </packageSources> <activePackageSource> <!-- this tells that all of them are active --> <add key="All" value="(Aggregate source)" /> </activePackageSource> </configuration> If the solution is open in Visual Studio, close it, then re-open it.
现在您的包应该出现在浏览器中,或者可以使用Install-Package进行安装
只是给一个更新,Visual Studio 2015用户有一些小的变化。
手动使用或安装包,请进入“工具->选项-> NuGet包管理器->包源”
点击“添加”按钮,选择“源”,不要忘记点击“更新”,因为它会更新你的包的文件夹位置,如果你想编辑你想要的包源名称:
要选择添加的包,请右键单击解决方案并选择“管理Nuget包”
右边是下拉列表,然后选择“浏览”以浏览您在文件夹源上指定的包。如果该文件夹源上没有nuget包,这将是空的:
推荐文章
- 如何在。net中创建和使用资源
- 如何在没有任何错误或警告的情况下找到构建失败的原因
- Visual Studio弹出提示:“操作无法完成”
- 为什么我在我的Excel插件中得到“无法在证书存储中找到清单签名证书”?
- Visual Studio拒绝忘记断点?
- Visual Studio展开/折叠键盘快捷键
- Visual Studio:如何在两个单独的选项卡组中看到相同的文件?
- 为什么visual studio 2012找不到我的测试?
- Visual Studio 2010 - c++项目-删除*。自卫队文件
- 如何在Visual Studio中删除未推送的外向提交?
- “无法写入文件…”因为它会覆盖输入文件。”
- 使用Visual Studio调试器在值更改时中断
- Visual Studio 2017:显示方法参考
- 为什么ReSharper想要使用'var'的一切?
- 在Visual Studio中默认从项目中删除安全警告(_CRT_SECURE_NO_WARNINGS)