I am having problems with NuGet: it's actually driving me crazy!
I am trying to make a TFS build run for a solution that includes nuget.exe.
I don't have any issues running it from Visual Studio on my local workstation, but when I queue a new build in the TFS server, the build fails with these very known errors:
D:\<...SolutionPath...>.nuget\nuget.targets (88): Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.
D:\<...SolutionPath...>.nuget\nuget.targets (88): The command ""D:\<...SolutionPath...>.nuget\nuget.exe" install "D:\<...SolutionPath...>\packages.config" -source "" -RequireConsent -solutionDir "D:\<...SolutionPath...>\ "" exited with code 1.
The problem is: I already set the EnableNuGetPackageRestore to true in the TFS Build server, but it's still throwing the same error. I also tried running nuget.exe with the same parameters FROM a cmd windows in the same TFS server and I don't have any issues.
BTW, this is the content of my NuGet.config:
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageRestore>
<add key="enabled" value="true" />
</packageRestore>
</configuration>
Any ideas?
Thanks in advance.
Please check that your TFS build service account is the same as the account you used to make the change. Also reboot the server to make sure the environment variable makes it the service.
Log on to the build server using the same account that executes the build.
Open Visual Studio.
Install the NuGet package manager in Visual Studio.
Restart Visual Studio.
Tools --> Options --> Package Manager --> General: tick 'Allow NuGet to download missing packages during build'.
Enable package restore in your solution.
Related
I have a Azure DevOps build pipeline that runs as expected on a hosted vs2017 agent, but fails on a self-hosted agent.
The error I get in the Visual Studio build step is:
C:\WINDOWS\TEMP\.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,20): Error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
The two agents seems to run the same version of msbuild.
From the diagnostic output from msbuild I can see that the output from the ResolvePackageDependencies task contains a lot of packages where the ResolvedPath is empty, for instance:
runtime.native.System/4.3.0
Name=runtime.native.System
Path=runtime.native.system/4.3.0
ResolvedPath=
Type=package
Version=4.3.0
But the NuGet restore step seems to complete without problems.
Any suggestions for what I am missing?
I believe I had a similar issue. I ended up having to install the latest Nuget and then run Nuget on the solution including a NuGet.config file.
Add a nuget.config to your solution so it is part of your repo/pull. Mine is in the same directory as the solution file. Example below
Add a task "NuGet Tool Installer" - I install NuGet 4.4.1, just put 4.4.1 in the Version to install input.
Add a task "NuGet Installer" - Different from above. Version 0.* - I have not tried the other versions.
Set the Path to the solution. IE. $(Build.Repository.LocalPath)/Source/Sample.sln
Add the path to the Nuget config file. Example $(Build.Repository.LocalPath)/Source/nuget.config
Nuget.config contains how to get the packages. Add other locations if you get packages from other sources like a local folder or something.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Used to specify the default Sources for list, install and update.
See: nuget.exe help list
See: nuget.exe help install
See: nuget.exe help update
-->
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
Your build task should run fine now and find all the packages.
Self-hosted Azure Devops build cant resolve packages
According to the error message, it seem nuget not restore the reference from SDK.
To resolve this issue, we need update our nuget.exe version to 4.0 and above.
In the NuGet tool installer we could specify the nuget.exe version:
As you comment above, it seems you have already use nuget installer, in this case, you can try to update Visual Studio to 15.3 and above on the build server. Because VS only adds proper support for .NET Core 2.0 SDK in version 15.3.
Finally, if your project/solution is .net core/standard you can use dotnet restore and then run dotnet build to compile your app.
Hope this helps.
I am using nexus OSS 3.15.2-01 and its new instance.
Issue we are facing is with nuget proxy repos, if i try it manually curl nuget org on nexus server it reaches the URL. but when i try to download it from VS or from cmd it says file not found.
I have created a seperate blob for nuget and new repo nuget_gallery, and provided the nuget org in proxy configuring it but its not working
From VS it says,
Severity Code Description Project File Line Suppression State
Error The feed ‘nexus prod [repo URL]’ lists package ‘Microsoft.AspNet.WebApi.Client.5.2.7’ but multiple attempts to download the nupkg have failed. The feed is either invalid or required packages were removed while the current operation was in progress. Verify the package exists on the feed and try again.
Unable to find package ‘Microsoft.AspNet.WebApi.Client.5.2.7’.
How ever the version is fetched in nexus if we browse the repo but even when we try to download it says file not found (0 bytes)
Bit late to the party, but I had this same problem. It seems to be down to lack of NuGet protocol 3 support in Nexus.
Workaround was to add protocolVersion="2" to my nuget.config like this;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="your-nexus-repo" value="http://your-nexus-repo/nexus/service/local/nuget/your-repo-name/" protocolVersion="2"/>
</packageSources>
</configuration>
I still had problems with dotnet core 3 packages, so also had to add back nuget.org (or remove <clear/> if nuget.org is in your global config)
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
You can try tips below to check if it helps:
1.Clean all the NuGet package cache by the command line: nuget locals all -clear.
2.Close all Visual Studio instance, then delete nuget.config file in the location: C:\Users\xxx\AppData\Roaming\NuGet\NuGet.Config, then re-open the Visual Studio to restore nuget packages.
3.Check if there is a firewall policy or other proxy settings that block the nuget installation package.
And please check if the issue only occurs when featching packages from Nexus or it also occurs when you download packages from nuget.org. Maybe you can get some help from this thread.
On my build server in my prebuild script I want to get all packages required for the solution.
Why? Because this happens:
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 ..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets.
According to Nuget documentation package restore should happen as part of the TFS 2013 build - but quite obviously it does not.
I tried to implement this as a prebuild action (custom script execution).
Whenever I try to run nuget on the build server this is what happens:
PS D:\ws\more\txs04\Data\Services\MyProject\.nuget> .\nuget.exe
An existing connection was forcibly closed by the remote host
Obviously a proxy issue. Unfortunately I didn't find any solution for this. I logged on as the build user and changed the proxy settings. I also tried environment variables - and the nuget configuration options. However since I cannot even invoke nuget.exe config this is kind of not an option.
Edit: I can reproduce this behavior on my development machine (where nuget usually works). runas /user:dev\tfsbuild powershell Next I try to execute nuget.exe and the above mentioned error occurs. It does not occur if I login with the tfsbuild user however.
I was having a similar issue running the nuget restore command from a target in my build .proj file.
<Target Name="RestorePackages">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "$(SourceHome)SolutionFile.sln"" />
</Target>
I added two additional parameters which resolved the issue for me:
-NonInteractive
-RequireConsent
<Target Name="RestorePackages">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "$(SourceHome)SolutionFile.sln" -NonInteractive -RequireConsent " />
</Target>
Hope this helps anyone else that runs into this.
I know that NuGet restoration could place checkout locks on the package folder and the contained files. But why does TFS Build not release those locks in the event of Gated Checkin Build failing due to compilation errors?
When Gated Checkin Build fails, Visual Studio does not allow to unshelve changes because files are locked by TFS service on the build server.
TFS Sidekick shows multiple files being locked by TFS service account.
If your solution is set to restore NuGet Packages you don't need to check packages into TFS as they will be restored on the build, Setting your solution to Restore packages will stop TFS from trying to add packages to the packages folder.
As MrHinsh says, Your packages folder within TFS should contain nothing more than the Config file
Option 1: You need to adds .tfignore to the packages folder with "*/" as a filter. You effectively don't ever want to check anything in under this folder other than the config file.
http://msdn.microsoft.com/en-us/library/ms245454.aspx
Option 2: (Better) Add a nuget.config file to your solution, convention is to place it under a folder named .nuget - but it can stay at root too. Content should be:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
That will exclude the packages folder, you don't need anything in there. NOTE: If you're using NuGet 2.7 or above, automatic restore is on by default. Don't use the "Enable NuGet Restore" in your solution, it adds the old way of doing this. See http://geekswithblogs.net/terje/archive/2014/06/11/converting-projects-to-use-automatic-nuget-restore.aspx
I am using PostSharp and I have the following target description in my project file:
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
<Error Condition="!Exists('..\..\packages\PostSharp.3.1.33\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://www.postsharp.net/links/nuget-restore." />
<Error Condition="Exists('..\..\packages\PostSharp.3.1.33\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
</Target>
As far as I understand, this is added to the project when PostSharp is referenced through NuGet, and the error conditions check the following:
The first error condition breaks the build when PostSharp is not available (i.e. NuGet did not restore it successfully).
The second error condition breaks the build when PostSharp was successfully restored by NuGet on the last build but was therefore not included in the project, so therefore a rebuild is necessary.
BUT, if I have the following configuration in NuGet.Config and .csproj file, is the second error condition even necessary?
NuGet.Config file:
<configuration>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
...
</configuration>
.csproj file:
<RestorePackages>true</RestorePackages>
As far as I understand, NuGet will then restore the missing packages BEFORE the build even starts. The second error condition will essentially break the build for no reason at all.
Note: I am using Visual Studio 2013 and NuGet 2.8.
It depends on how the restore is done and which version of NuGet you have installed. It looks like the error messages are trying to cover three scenarios:
Building without the MSBuild based package restore enabled (which is configured inside Visual Studio by right clicking the solution and selecting Enable Package restore).
Building outside of Visual Studio when the MSBuild based package restore is not enabled.
Building with Visual Studio using an old version of NuGet which does not support the automatic restore before a build.
If you are using the MSBuild based package restore then the restore will occur during the build and the PostSharp files will not be imported at this point so the $(PostSharp30Imported) will be empty and the second error message will be displayed. At least I suspect that is the case.
If you building from the command line and not using the MSBuild based package restore then you would see the first error message if the NuGet packages were missing.
If you are not using the MSBuild based package restore, and are building from within Visual Studio with a recent version of NuGet, then you are correct that the packages will be restored before anything is built at all. So the PostSharp imports should be available to MSBuild before it is even executed.
As PostSharp dlls are required during msbuild loading (so targets referencing this dlls are available during build) they must be available during final call to msbuild.
While in VS it is acceptable to click build twice, I was using PostSharp in CI environment, and requirement to call build on solution two times was frustrating (first build restore nugets but also failed build due to error).
I ended up with separate build steps:
Restore nuget Packages (this downloads PostSharp packages and return success code to environment):
NuGet.exe restore SolutionWithProjectsUsingPostSharp.sln
Build solution.
You need to edit the second error condition in the target in the csproj
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
<Error Condition="!Exists('....\packages\PostSharp.3.1.33\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://www.postsharp.net/links/nuget-restore." />
<Error Condition="Exists('....\packages\PostSharp.3.1.33\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
</Target>>
I have answered in detail in a different post at SO
We are using 'old' MSBuild-Integrated package restore ( .nuget\NuGet.targets file is present) and normally do not store in source control packages, but rely on build to restore them for each build.
But for PostSharp on TeamCity build server I am getting error :
The build restored NuGet packages. Build the project again to include
these packages in the build.
The simplest way is to explicitly include in source control packages\PostSharp.VerXXX.
Alternatively solution could be migrating to automatic package restore,
as it was advised in Issue Using PostSharp 3.x with NuGet Auto Restore
Right click on the solution, Manage Nuget packages; and remove the packages you dont want .
This error also shows up , when trying to restore the packages from the web. Just connect your self to the internet and then try opening the project.
The errors went away for me on following the above steps.