NuGet 자동 패키지 복원이 MSBuild에서 작동하지 않음
MSBuild 12.0을 사용 하여 packages
콘텐츠가 누락 된 ( repositories.config
내부 제외 ) 솔루션을 구축하려고합니다 . 빌드하기 전에 누락 된 모든 패키지를 자동으로 복원 할 것으로 예상하지만 이것은 사실이 아닙니다. MsBuild는 수많은 오류를보고합니다.
"사용 지시문이나 어셈블리 참조가 누락 되었습니까?"
NuGet Manager는 2.7입니다 (박스에 대한 Visual Studio 2013에서 볼 수 있음). 나는 심지어 EnableNuGetPackageRestore=true
매개 변수 를 전달하려고 시도했습니다 -운이 없습니다. 내가 무엇을 놓치고 있습니까?
v3.3.0부터 최신 공식 NuGet 문서로 업데이트 됨
패키지 복원 접근 방식
NuGet은 패키지 복원 사용에 대한 세 가지 접근 방식을 제공합니다 .
자동 패키지 복원 은 Visual Studio 내에서 패키지 복원 에 대한 NuGet 팀의 권장 접근 방식이며 NuGet 2.7에 도입되었습니다. NuGet 2.7부터 NuGet Visual Studio 확장은 Visual Studio의 빌드 이벤트에 통합되고 빌드가 시작될 때 누락 된 패키지를 복원합니다. 이 기능은 기본적으로 활성화되어 있지만 개발자는 원하는 경우 옵트 아웃 할 수 있습니다.
작동 방식은 다음과 같습니다.
- 프로젝트 또는 솔루션 빌드에서 Visual Studio는 솔루션 내에서 빌드가 시작된다는 이벤트를 발생시킵니다.
- NuGet은이 이벤트에 응답하고 솔루션에 포함 된 packages.config 파일을 확인합니다.
- 찾은 각 packages.config 파일에 대해 패키지가 열거되고 Checked for가 솔루션의 패키지 폴더에 있습니다.
- 누락 된 패키지는 패키지 소스의 순서에 따라 사용자의 구성 (및 활성화 된) 패키지 소스에서 다운로드됩니다.
- 패키지가 다운로드되면 솔루션의 패키지 폴더에 압축이 풀립니다.
Nuget 2.7+가 설치되어있는 경우; Visual Studio에서 자동 패키지 복원 관리를위한 한 가지 방법을 선택하는 것이 중요합니다.
두 가지 방법을 사용할 수 있습니다.
- (Nuget 2.7 이상) : Visual Studio-> 도구-> 패키지 관리자-> 패키지 관리자 설정-> 자동 패키지 복원 활성화
- (Nuget 2.6 이하) 솔루션을 마우스 오른쪽 버튼으로 클릭하고 "이 솔루션에 대한 패키지 복원 활성화"를 클릭합니다.
명령 줄 에서 솔루션을 빌드 할 때 명령 줄 패키지 복원 이 필요합니다. NuGet의 초기 버전에서 도입되었지만 NuGet 2.7에서는 개선되었습니다.
nuget.exe restore contoso.sln
MSBuild 통합 패키지 복원 접근 방식은 원래 패키지 복원 구현이며 많은 시나리오에서 계속 작동하지만 다른 두 접근 방식으로 해결되는 전체 시나리오 세트를 다루지는 않습니다.
MSBuild 15와 함께 제공되는 Visual Studio 2017을 사용 하고 .csproj 파일이 새 PackageReference
형식 인 경우 가장 간단한 방법은 새 MSBuild Restore
대상 을 사용하는 것 입니다.
아무도 실제로 "MSBuild를 사용하여 명령 줄에서 빌드 할 때 NuGet 패키지를 자동으로 복원하려면 어떻게해야합니까?"라는 원래 질문에 대답하지 않았습니다. 대답은 다음과 같습니다. "NuGet 패키지 복원 활성화"옵션 ( 이 참조에 따라 더 이상 사용되지 않음)을 사용 하지 않는 한 사용할 수 없습니다 (아래 참조). 예를 들어 CI 서버에서 자동화 된 빌드를하려는 경우 이건 짜증납니다.
그러나 원하는 동작을 얻을 수있는 약간의 우회 방법이 있습니다.
- https://dist.nuget.org/win-x86-commandline/latest/nuget.exe 에서 최신 NuGet 실행 파일을 다운로드하고 PATH에 배치합니다. (이 작업은 사전 빌드 단계로 수행 할 수 있습니다.)
nuget restore
누락 된 모든 패키지를 자동 다운로드하는 실행 합니다.msbuild
솔루션을 빌드하려면 실행하십시오 .
곁에 : 자동 패키지 복원을 수행하는 새롭고 권장되는 방법은 버전 제어가 덜 복잡하지만 다운로드 및 실행이라는 추가 단계를 거치지 않는 한 명령 줄 패키지 복원을 불가능하게 만듭니다 nuget.exe
. 진행?
Nuget의 자동 패키지 복원은 MSBuild가 아닌 Visual Studio (2013 년부터 시작)의 기능입니다. nuget.exe restore
명령 줄에서 패키지를 복원 하려면 실행 해야합니다.
Nuget 패키지 복원 사용 기능을 사용할 수도 있지만 프로젝트 파일을 방해하는 변경을 수행하고 다른 솔루션에서 해당 프로젝트를 빌드하는 경우 문제가 발생할 수 있으므로 더 이상 Nuget 사용자가 권장하지 않습니다.
전체 사진을 파악하는 데 시간이 좀 걸렸고 여기서 공유하고 싶습니다.
Visual Studio에는 패키지 복원을 사용하는 두 가지 방법, 즉 자동 패키지 복원과 MSBuild 통합 패키지 복원이 있습니다. 'MSBuild 통합 패키지 복원'은 일부 시나리오에서 문제를 일으킬 수있는 빌드 프로세스 동안 패키지를 복원합니다. NuGet 팀 에서 권장하는 접근 방식 은 '자동 패키지 복원'입니다 .
'자동 패키지 복원'이 작동하도록하려면 몇 가지 단계가 있습니다.
Visual Studio, 도구-> 확장 및 업데이트에서 최신 버전 (버전 2.7 이상)이있는 경우 NuGet을 업그레이드합니다.
TFS를 사용하는 경우 솔루션의 .nuget 폴더에서 NuGet.exe 및 NuGet.targes 파일을 제거합니다. 그런 다음 NuGet 패키지를 체크인하지 않도록 NuGet.Config를 편집합니다.
<configuration> <solution> <add key="disableSourceControlIntegration" value="true" /> </solution> </configuration>
If you checked in the solution's packages folder to TFS before, delete the folder and check in the deletion of package folder deletion.
If you don't use TFS, delete the .nuget folder.
In each project file (.csproj or .vbproj) in your solution, remove the line that references NuGet.targets file. The reference looks like this:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Remove this line in every project file in your solution.
In Visual Studio menu, either through
Tools -> Options -> Package Manager -> General or Tools -> NuGet Package Manager -> Package Manager Settings
please enable the following two options 1) 'Allow NuGet to download missing packages' 2) 'Automatically check for missing packages during build in Visual Studio'
Test your package restore configuration by the following steps
- Save your solution and close Visual Studio
- Delete your solution's packages folder
- Start Visual Studio, open your solution and rebuild it.
MSBuild 15 has a /t:restore option that does this. it comes with Visual Studio 2017.
If you want to use this, you also have to use the new PackageReference, which means replacing the packages.config
file with elements like this (do this in *.csproj):
<ItemGroup>
<!-- ... -->
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" />
<!-- ... -->
</ItemGroup>
There is an automated migration to this format if you right click on 'References' (it might not show up if you just opened visual studio, rebuild or open up the 'Manage NuGet packages for solution' window and it will start appearing).
Ian Kemp has the answer (have some points btw..), this is to simply add some meat to one of his steps.
The reason I ended up here was that dev's machines were building fine, but the build server simply wasn't pulling down the packages required (empty packages folder) and therefore the build was failing. Logging onto the build server and manually building the solution worked, however.
To fulfil the second of Ians 3 point steps (running nuget restore), you can create an MSBuild target running the exec command to run the nuget restore command, as below (in this case nuget.exe is in the .nuget folder, rather than on the path), which can then be run in a TeamCity build step (other CI available...) immediately prior to building the solution
<Target Name="BeforeBuild">
<Exec Command="..\.nuget\nuget restore ..\MySolution.sln"/>
</Target>
For the record I'd already tried the "nuget installer" runner type but this step was hanging on web projects (worked for DLL's and Windows projects)
Note that if you are using TeamCity as a build server, you get a "NuGet Installer" step that you can use to restore all the packages before the build step.
There is a packages.config file with the project, it contains the package details.
Also there is a .nuget folder which contains the NuGet.exe and NuGet.targets. if any one of the file is missing it will not restore the missing package and cause "are you missing a using directive or an assembly reference?" error
Sometimes this occurs when you have the folder of the package you are trying to restore inside the "packages" folder (i.e. "Packages/EntityFramework.6.0.0/") but the "DLLs" are not inside it (most of the version control systems automatically ignore ".dll" files). This occurs because before NuGet tries to restore each package it checks if the folders already exist, so if it exists, NuGet assumes that the "dll" is inside it. So if this is the problem for you just delete the folder that NuGet will restore it correctly.
In Visual Studio 2017 - When you compile using IDE - It will download all the missing nuget packages and save in the folder "packages".
But on the build machine compilation was done using msbuild.exe. In that case, I downloaded nuget.exe and kept in path.
During each build process before executing msbuild.exe. It will execute -> nuget.exe restore NAME_OF_SLN_File (if there is only one .SLN file then you can ignore that parameter)
I had an issue with nuget packages not being included in a scripted nightly build that builds the sln file using devenv.exe.
I followed the advice from Microsoft, and the key step was updating the NuGet config in %AppData%/NuGet
so that it contained:
<configuration>
<packageRestore>
<add key="automatic" value="True" />
</packageRestore>
</configuration>
You can also use
Update-Package -reinstall
to restore the NuGet packages on the Package Management Console in Visual Studio.
참고URL : https://stackoverflow.com/questions/22300375/nuget-auto-package-restore-does-not-work-with-msbuild
'Programming' 카테고리의 다른 글
효과가 끝날 때까지 jQuery를 기다리는 방법은 무엇입니까? (0) | 2020.08.10 |
---|---|
Laravel 5-HTTPS로 리디렉션 (0) | 2020.08.10 |
제약 조건이 높이 0을 모호하게 제안하는 경우 감지 (0) | 2020.08.10 |
Netbeans 성능을 향상시키는 방법은 무엇입니까? (0) | 2020.08.09 |
PhoneGap Eclipse 문제-eglCodecCommon glUtilsParamSize : 알 수없는 매개 변수 오류 (0) | 2020.08.09 |