我来自Maven世界,您可以从本地存储库(可以从公共存储库更新)读取每个项目/解决方案,并将私有代码项目发布到存储库。
所以,例如:
所以同样,我试图通过使用:
为我的.NET项目保留一个本地存储库<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- My specific and common packages can be sourced from this folder -->
<add key="My Package Source" value="C:\sourcecode\CommonDLLs" />
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
</packageSources>
...
<config>
<!-- Install packages in this folder instead of default $(Solutiondir)\Packages -->
<add key="repositorypath" value="C:\sourcecode\CommonDLLs" />
</config>
</configuration>
为了测试这个,我打包了一个程序集,为我的项目创建了MyProject.dll.1.0.0.nupkg文件。
然后在Visual Studio中,我选择了另一个项目并选择了Manage NuGet Packages ...我看到了MyProject.dll和一个Install按钮。
然后我得到错误:
'MyProject.dll 1.0.0' already installed.
Adding 'MyProject.dll 1.0.0' to MyTestProject.
Uninstalling 'MyProject.dll 1.0.0'.
Successfully uninstalled 'MyProject.dll 1.0.0'.
**Failed to add reference to 'MyProject'.**
我认为它与package source和respositoryPath的路径有关,但是想确认一下。真正?为什么这不起作用?从理论上讲,我会有一个本地存储库。
更新: 我尝试将配置指向不同的目录。我仍然得到同样的错误。
所以必须是我如何构建本地存储库文件和/或它们所在的位置:
我有一个dll,MyProject.dll: 第1步:运行nuget命令 nuget spec MyProject.dll(位于文件夹&#39; lib&#39;) 第2步:编辑nuget spec文件 编辑.nuspec文件 第3步:运行nuget命令 nuget pack MyProject.nuspec
这让我在我的文件夹中有3个项目: MyProject.dll.nuspec LIB / MyProject.dll MyProject.dll.1.0.0.nupkg
我尝试将.nupkg单独放在packageSources指向的路径上。还是一样的错误。
万分感谢!
更新#2 :
以下是PM控制台中运行安装的堆栈跟踪:
PM> install-package -source c:\sourcecode\createcommon MyProject.dll
'MyProject.dll 1.0.0' already installed.
Adding 'MyProject.dll 1.0.0' to MyTestProject.
Uninstalling 'MyProject.dll 1.0.0'.
Successfully uninstalled 'MyProject.dll 1.0.0'.
Install-Package : Failed to add reference to 'MyProject'.
At line:1 char:16
+ install-package <<<< -source c:\sourcecode\createcommon MyProject.dll
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
PM> $error[0].Exception.StackTrace
at NuGet.VisualStudio.VsProjectSystem.AddReference(String referencePath, Stream stream)
at NuGet.ProjectManager.ExtractPackageFilesToProject(IPackage package)
at NuGet.ProjectManager.AddPackageReferenceToProject(IPackage package)
at NuGet.ProjectManager.Execute(PackageOperation operation)
at NuGet.ProjectManager.Execute(IPackage package, IPackageOperationResolver resolver)
at NuGet.ProjectManager.AddPackageReference(IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass60.<AddPackageReference>b__5f()
at NuGet.VisualStudio.VsPackageManager.RunProjectAction(IProjectManager projectManager, Action action)
at NuGet.VisualStudio.VsPackageManager.AddPackageReference(IProjectManager projectManager, IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass8.<InstallPackage>b__4()
at NuGet.VisualStudio.VsPackageManager.RunSolutionAction(Action action)
at NuGet.VisualStudio.VsPackageManager.InstallPackage(IProjectManager projectManager, String packageId, SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions, Boolean skipAssemblyReferences, ILogger logger)
at NuGet.VisualStudio.VsPackageManager.InstallPackage(IProjectManager projectManager, String packageId, SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions, ILogger logger)
at NuGet.PowerShell.Commands.InstallPackageCommand.InstallPackage(IVsPackageManager packageManager)
at NuGet.PowerShell.Commands.InstallPackageCommand.ProcessRecordCore()
at NuGet.PowerShell.Commands.NuGetBaseCommand.ProcessRecord()
PM>
内部异常:
System.InvalidOperationException: Failed to add reference to 'Utility'. --->
System.Runtime.InteropServices.COMException:
Error HRESULT E_FAIL has been returned from a call to a COM component.
at VSLangProj.References.Add(String bstrPath)
at NuGet.VisualStudio.VsProjectSystem.AddReference(String referencePath, Stream stream)
--- End of inner exception stack trace ---