TFS 2013 Not Restoring NuGet Packages - visual-studio-2013

According to the NuGet Documentation, NuGet package restore should "just work" with TFS 2013.
It's not.
When the build machine runs, it gives me the following error (where it can't find Newtonsoft.Json)
Program.cs (5): The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
This is with a brand new project, on TFS 2013 using the default template(TfvcTemplate.12.xaml). I'm using VS 2013. Honestly, I'm new to TFS so I'm not sure what a build log should look like, but mine looks like this:
Overall Build Process
Overall build process
Update build number
Run on agent (reserved build agent CTIDEV2k8 - Agent1)
Initialize environment
Get sources from Team Foundation Version Control
Associate the changesets that occurred since the last good build
Compile, Test and Publish
Run optional script before MSBuild
Run MSBuild
Built $/Web/TestApp/TestApp.sln for default targets.
Built $/Web/TestApp/TestApp/TestApp.csproj for default targets.
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets (1697): Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Program.cs (5): The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
MSBuild Log File
Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException)
Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Handle Exception
Create a bug for the build failure
Rethrow the exception so the build will stop
Perform Final Actions On Agent
Copy binaries to drop
Reset the Environment
Work item '96: Build Failure in Build: TestApp2_20150224.2' was opened by the build.
Does anyone know anything about this?

The issue turned out to be that we had an internal Nuget package feed. The issue was fixed by adding a nuget.config file to the root of the solution folder:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="InternalFeed" value="https://our.nuget.com" />
</packageSources>
<activePackageSource>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</activePackageSource>
</configuration>

Are you sure that Package Restore is enabled in the Visual Studio on your Build Server? The Build Server can reach nuget.org? You can open the TestApp.sln on your Build Server and try to compile this manually. Does this work?

Related

How to add new packages when using an Azure Artifcat as package source

Due to our obfuscasting library(Babel4), we had to create a Azure artifact to host their nuget package.
It works fine, but if we try to add a package that has never been referenced in our .Net Core project(in visual studio), we cannot find it.
I was able to manually install it through the command line:
Install-Package Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson
but then on another computer if I try to restore the references, I get this error:
XXX.YYY: [NU1101] Unable to find package
Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson. No packages exist with this id in source(s): Babel3
(Babel3 is our artifact name).
But Azure Artifacts has Nuget(and other) configured as upstream sources:
On Azure Artifact, if I try to look for a package that I don't have installed, it doesn't find it(and I'm owner of the artifact):
What should I do? Configure another package source in Visual Studio? Something on azure?
Thank you very much
EDIT
Here is is my nuget.config if it helps:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="Babel3" value="https://pkgs.dev.azure.com/XXXXX/_packaging/Babel3/nuget/v3/index.json" />
</packageSources>
<config>
<add key="repositoryPath" value="packages\" />
<add key="globalPackagesFolder" value="packages\" />
</config>
</configuration>
Please go to Feed settings for Babel3 -> Check if you have added "Project Collection Build Service(org)" and "project build service(org)" as collaborator, contributor, or owner role. As per the doc, if you don't have enough permission on feed, the pipeline cannot fetch package from upstream.
I can fetch the nuget package from upstream to local feed.
BTW, please make sure the project settings -> pipelines -> settings -> Job authroized scope is not limited if the feed from another project.
Edit:
Since you restore from local machine and "nuget gallery" is public resource. Please try to add it directly in nuget.config.

Self-hosted Azure Devops build cant resolve packages

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.

TFS Build error using visual studio 2015

i have problem with TFS build, all time its failed with different type of errors, i resolved mostly, but still there are errors, i am not sure why these are and how these will resolve. i am sorry i can not explain more in detail.
error 1
C:\Builds\1\SmallBiz\SmallBiz-Web\Sources\SmallBiz.Web\SmallBiz.Web.csproj
(9921): 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 ..\.nuget\NuGet.targets.
error 2
Exception Message: MSBuild error 1 has ended this build. You can find
more specific information about the cause of this error in above
messages. (type BuildProcessTerminateException) Exception Stack Trace:
at System.Activities.Statements.Throw.Execute(CodeActivityContext
context) at
System.Activities.CodeActivity.InternalExecute(ActivityInstance
instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at
System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
executor, BookmarkManager bookmarkManager, Location resultLocation)
errors image
please help me or guide me, where i am wrong, what i am missing in configuration. i appreciate your valuable time and effort, thanks in advance.
finally i resolved my problem to remove the following tags or lines in .csproj file
right click on project unload it
right click on project to edit project file and remove the below code
1. <RestorePackages>true</RestorePackages>
2. <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
3. <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>
under the solution Delete .nuget files from source control
reload project and build it
check in changes

NuGet restoring PostSharp package before the build begins

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.

VS 2010 Beta 2 - unable to update service reference

I'm upgrading a project from VS2008 to VS2010B2
For some reason, after the project was upgraded, the code generated by the reference is missing, and I cannot re-create the code by reconfiguring the service reference, because I'm getting the following error:
The configuration for the service
reference could not be updated due to
the following issue: An error occurred
creating the configuration section
handler for
system.serviceModel/behaviors:
Extension element 'webHttp' cannot be
added to this element. Verify that
the extension is registered in the
extension collection at
system.serviceModel/extensions/behaviorExtensions.
The machine has the configuration for webHttp:
<system.serviceModel>
<extensions>
<behaviorExtensions>
...
<add name="webHttp" type="System.ServiceModel.Configuration.WebHttpElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
...
</behaviorExtensions>
...
Try:
Right-click on the solution, Clean;
Right-click the web reference, Update Web reference;
Right-click on the solution, Rebuild.

Resources