我有一些c#书中的。nupkg文件。我如何安装它们?
当前回答
菜单工具→选项→包管理器
给出名称和文件夹位置。单击OK。将您的NuGet包文件放在该文件夹中。
转到解决方案资源管理器中的项目,右键单击并选择“管理NuGet包”。选择新的包源。
这里是文档。
其他回答
只是给一个更新,Visual Studio 2015用户有一些小的变化。
手动使用或安装包,请进入“工具->选项-> NuGet包管理器->包源”
点击“添加”按钮,选择“源”,不要忘记点击“更新”,因为它会更新你的包的文件夹位置,如果你想编辑你想要的包源名称:
要选择添加的包,请右键单击解决方案并选择“管理Nuget包”
右边是下拉列表,然后选择“浏览”以浏览您在文件夹源上指定的包。如果该文件夹源上没有nuget包,这将是空的:
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进行安装
对于.nupkg文件,我喜欢使用:
Install-Package C:\Path\To\Some\File.nupkg
用于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.
如果你有一个.nupkg文件,只需要.dll文件,你所要做的就是将扩展名更改为.zip,然后找到lib目录。
推荐文章
- 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
- 为什么Visual Studio 2015/2017/2019测试运行器没有发现我的xUnit v2测试
- Visual Studio复制项目
- 如何在iis7应用程序池中设置。net Framework 4.5版本
- Visual Studio - Resx文件默认“内部”为“公共”
- 在Visual Studio 2010中有快速查找文件的方法吗?
- Nuget连接尝试失败“无法为源加载服务索引”
- 在Visual Studio中查看多个项目/解决方案
- Visual Studio打开默认浏览器,而不是Internet Explorer
- csproj文件中的“Service Include”是干什么用的?
- 如何在Visual Studio中找到堆栈跟踪?
- 使用不同的Web。在开发和生产环境中进行配置
- 是否有一种方法可以在Visual Studio中删除一行而不剪切它?
- Microsoft Visual Studio的推荐插件
- Visual Studio: ContextSwitchDeadlock