Programming

NuGet 패키지 복원이 작동하지 않습니다

procodes 2020. 6. 4. 21:24
반응형

NuGet 패키지 복원이 작동하지 않습니다


한 컴퓨터에서 프로젝트를 체크인하고 다른 컴퓨터에서 체크 아웃했으며 NuGet이 설치 한 바이너리가 누락 된 것을 발견했습니다. 소스 제어도 확인할 수 있지만 더 나은 해결책이있는 것 같습니다.

http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

나는 그 지침을 따랐으며 이제 .nuget폴더가 있어야하며 내 .csproj 파일에 다음 항목이 있습니다.

<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

그러나 솔루션을 다시 빌드 할 때 누락 된 패키지는 복원되지 않습니다.

내가 무엇을 놓치고 있습니까? 이 문제를 어떻게 진단 할 수 있습니까?


nuget 패키지 관리자 콘솔에서 다음 명령을 실행하여 패키지 복원을 강제 실행할 수 있습니다.

업데이트 패키지-다시 설치

솔루션의 모든 것을 강제로 다시 설치합니다.


업데이트 패키지-재설치-ProjectName myProj

myProj 프로젝트의 모든 것을 강제로 다시 설치합니다.

참고 : 이것은 핵 옵션입니다. 이 명령을 사용할 때 설치 한 것과 동일한 버전의 패키지를 얻지 못할 수 있으며 이로 인해 문제가 발생할 수 있습니다. 솔루션 수준이 아니라 프로젝트 수준에서 발생할 가능성이 적습니다.

-safe명령 행 매개 변수 옵션을 사용하여 동일한 주 및 부 버전 구성 요소가있는 최신 버전으로의 업그레이드를 제한 할 수 있습니다 . 이 옵션은 나중에 추가되어 주석에 언급 된 일부 문제를 해결합니다.

업데이트 패키지-재설치-안전


이 게시물을 우연히 본 다른 사람들을 위해 이것을 읽으십시오.

NuGet 2.7+는 자동 패키지 복원 을 소개했습니다 . 이것은 MSBuild 프로세스를 변경하지 않기 때문에 대부분의 응용 프로그램에서 훨씬 더 나은 접근 방식으로 간주됩니다. 덜 두통.

시작할 수있는 몇 가지 링크 :


패키지 / 이진이없는 프로젝트에서 패키지 복원 모드를 활성화 했습니까? 복원 모드를 활성화 할 때 패키지를 올바르게 설치해야하는 알려진 문제가 있습니다.

http://nuget.codeplex.com/workitem/1879


원본 링크가 죽었습니다. 이것은 교체 일 수 있습니다 : https://github.com/NuGet/Home/issues/1968


다음 중 한 가지 방법을 선택해야합니다.

모든 솔루션 프로젝트에서 이름으로 패키지를 다시 설치하십시오.

Update-Package –reinstall <packageName>

이름으로 패키지를 다시 설치하고 모든 솔루션 프로젝트의 종속성을 무시하십시오.

Update-Package –reinstall <packageName> -ignoreDependencies

프로젝트에서 이름으로 패키지를 다시 설치하십시오.

Update-Package –reinstall <packageName> <projectName>

특정 프로젝트에서 모든 패키지를 다시 설치하십시오.

Update-Package -reinstall -ProjectName <projectName>

솔루션에서 모든 패키지를 다시 설치하십시오.

Update-Package -reinstall 

두 가지 시나리오 에서이 문제가 발생했습니다.

먼저 msbuild.exe를 사용하여 명령 줄에서 솔루션을 빌드하려고합니다. 둘째, TFS 및 CI를 사용하여 빌드 서버에서 sln 및 포함 프로젝트를 빌드하려고 할 때.

참조가 누락되었다고 주장하는 오류가 발생합니다. 로컬 빌드 디렉토리와 TFS 서버를 모두 검사 할 때 / packages 폴더가 생성되지 않고 nuget 패키지가 복사되지 않는 것을 알 수 있습니다. Alexandre의 답변에 나열된 지침에 따라 http://nuget.codeplex.com/workitem/1879 도 작동하지 않았습니다.

VS2010을 통해 패키지 복원을 활성화했으며 VS2010 내에서만 빌드가 작동하는 것을 보았습니다. 다시 말하지만 msbuild 사용이 실패합니다. 해결 방법은 완전히 유효하지 않지만 내 환경의 경우 명령 줄 빌드와 TFS의 CI 빌드에서 모든 것이 작동합니다.

. \ nuget으로 이동하여 .nuget \ NuGet.targets 파일에서이 줄을 변경했습니다.

에서:

<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" -o "$(PackagesDir)"</RestoreCommand>

to : (주의 사항, 변수 주위에 따옴표가 없음)

<RestoreCommand>$(NuGetCommand) install $(PackagesConfig) -source $(PackageSources) -o $(PackagesDir)</RestoreCommand>

내 디렉토리에 공백이 있으면 실패하지만 디렉토리에 공백이 없으므로이 해결 방법으로 빌드가 성공적으로 완료되었습니다 ... 당분간.

빌드에서 진단 수준 로깅을 설정하면 msbuild에서 실행중인 명령을 표시하는 데 도움이됩니다. 이것이 목표 파일을 일시적으로 해킹하게 한 것입니다.


VS 2017

도구> NuGet 패키지 관리자> 패키지 관리자 설정> 일반 "모든 NuGet 캐시 지우기"를 클릭하십시오.


다른 방법으로 문제가 해결되지 않으면 다음을 시도하십시오.

  1. 프로젝트를 닫습니다.
  2. 솔루션 폴더에서 패키지 폴더를 삭제하십시오.
  3. 프로젝트를 다시 열고 너겟 패키지를 다시 복원하십시오.

나를 위해 일했고 시도하기 쉽습니다.


나를 위해 .csproj에 빈 태그 NuGetPackageImportStamp가 있습니다.

<NuGetPackageImportStamp>
    </NuGetPackageImportStamp>

이상적인 GUID를 포함하는 것이 이상적입니다.

Removing the above said tag and then "Restore Nugets" worked for me.


Just for others that might run into this problem, I was able to resolve the issue by closing Visual Studio and reopening the project. When the project was loaded the packages were restored during the initialization phase.


If none of the other answers work for you then try the following which was the only thing that worked for me:

Find your .csproj file and edit it in a text editor.

Find the <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> tag in your .csproj file and delete the whole block.

Re-install all packages in the solution:

Update-Package -reinstall

After this your nuget packages should be restored, i think this might be a fringe case that only occurs when you move your project to a different location.


Sometimes something strange happens and using Visual Studio to automatically restore doesn't work. In that case you can use the NuGet Package Manager Console. That is opened within Visual Studio from Tools -> NuGet Package Manager -> Package Manager Console. The commands within the console are simple. And to get context help while typing a command just press the button and it will give you all options that start with the letters you're typing. So if a package isn't installed, for example log4net, type the following command:

Install-Package log4net

You can do a whole lot more, like specify the version to install, update a package, uninstall a package, etc.

I had to use the console to help me when Visual Studio was acting like a weirdo.


Automatic Package Restore will fail for any of the following reasons:

  1. You did not remove the NuGet.exe and NuGet.targets files from the solution's .nuget folder (which can be found in your solution root folder)
  2. You did not enable automatic package restore from the Tools >> Options >> Nuget Package Manager >> General settings.
  3. You forgot to manually remove references in all your projects to the Nuget.targets file
  4. You need to restart Visual Studio (make sure the process is killed from your task manager before starting up again).

The following article outlines in more detail how to go about points 1-3: https://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore


I had NuGet packages breaking after I did a System Restore on my system, backing it up about two days. (The NuGet packages had been installed in the meantime.) To fix it, I had to go to the .nuget\packages folder in my user profile, find the packages, and delete them. Only then would Visual Studio pull the packages down fresh and properly add them as references.


The best workaround that I found creating a new Project from scratch, then import all the source files with the code. My project was not so complicated so I had no problem from there.


In VS2017, right-click on the solution => Open CommandLine => Developer Command Line.

Once thats open, type in (and press enter after)

dotnet restore

That will restore any/all packages, and you get a nice console output of whats been done...


vs2015 no enable nuget restore problem. My solution:

  1. add folder .nuget, add file NuGet.Config and NuGet.targets in Directory .nuget

  2. each project file add: build

  <RestorePackages>true</RestorePackages>

  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

If the error you are facing is "unable to connect to remote server" as was mine, then it would benefit you to have this check as well in addition to the checks provided in the above comments.

I saw that there were 2 NUGET Package Sources from which the packages could be downloaded (within Tools->Nuget Package Manager->Packager Manager Settings). One of the Package Source's was not functioning and Nuget was trying to download from that source only.

Things fell into place once I changed the package source to download from: https://www.nuget.org/api/v2/ EXPLICTLY in the settings


In my case, an aborted Nuget restore-attempt had corrupted one of the packages.configfiles in the solution. I did not discover this before checking my git working tree. After reverting the changes in the file, Nuget restore was working again.


There is a shortcut to make Nuget restore work, 1. Make sure internet connection or Nuget urls are proper in VS Tools options menu 2. Look at .nuget or nuget folder in the solution, else - copy from any to get nuget.exe

  1. DELETE packages folders, if exists

  2. Open the Package manager console execute this command

    • paste full path of nuget.exe RESTORE full path of .sln file!
  3. use Install-pacakge command, if build did not get through for any missing references. Hope It Helps (HIH)

None of the other solutions worked in my situation:

AspNetCore dependencies had been installed/uninstalled and were being cached. 'AspNetCore.All' would refuse to properly update/reinstall/remove. And regardless of what i did, it would use the cached dependencies (that it was not compatible with), because they were a higher version.

  1. Backup Everything. Note the list of Dependencies you'll need to reinstall, Exit VisualStudio
  2. Open up all .proj files in a text editor and remove all PackageReference
  3. In each project, delete the bin, obj folders
  4. Delete any "packages" folders you find in the solution.
  5. Open solution, go into Tools > Nuget Package Manager > Package Manager Settings and Clear all Nuget caches. Check the console because it may fail to remove some items - copy the folder path and exit visual studio.
  6. Delete anything from that folder Reopen solution and start installing nuget packages again from scratch.

If that still doesn't work, repeat but also search your drive in windows explorer for nuget and delete anything cachey looking.

참고URL : https://stackoverflow.com/questions/9011889/nuget-package-restore-not-working

반응형