NuGet packages issue when building on TeamCity - visual-studio

I have some solution created in Visual Studio 2015, with usages of NuGet packages.
When I compile the solution from Visual Studio (both of settings "Allow to download missing packages"
and "Automatically check for missing packages during build" are set ON) - it works.
But when compiling the solution on TeamCity (which calls MSBuild for build) - it fails:
Error : the type or namespace name 'someName' cannot be found (are you missing using directive or assembly reference?), where 'someName' defined in the assembly to be installed by NuGet
In TeamCity there are two separate steps defined:
NuGet install - it was verified that packages installed on build agent
Build itself
Is there a parameter of MSBuild to be checked?
What can be the cause of the issue?

Error : the type or namespace name 'someName' cannot be found (are you missing using directive or assembly reference?) , where 'someName' defined in the assembly to be installed by Nuget
According to the error log, you need add a step to your build process to restore all NuGet packages. You can refer to the document NuGet Package Restore with TeamCity for more detail.

Related

.NET Core MSTest project can't find VisualStudio type or namespace in Microsoft namespace

Microsoft Visual Studio Professional 2019
Version 16.0.0
VisualStudio.16.Release/16.0.0+28729.10
I added a .NET Core 2.2 MSTest project and it added dependencies :
Microsoft.NET.Test.Sdk v16.0.1 ( I updated to v16.2.0 )
Microsoft.NET.Test.Sdk v1.3.2 ( I updated to v1.4.0 )
MSTest.TestFramework v1.3.2 ( I updated to v1.4.0 )
I compile and get this error :
CS0234 The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) ...\packages\microsoft.net.test.sdk\16.2.0\build\netcoreapp1.0\Microsoft.NET.Test.Sdk.Program.cs
Microsoft.NET.Test.Sdk.Program.cs
// <auto-generated> This file has been auto generated. </auto-generated>
using System;
[Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode]
class AutoGeneratedProgram {static void Main(string[] args){}}
Couple of observations :
Project is .NET Core 2.2 but it's using package from
netcoreapp1.0 folder
NuGet package manager successfully added package Microsoft.NET.Test.Sdk v16.0.1 but on build it has an unresolved
reference
The type or namespace name 'VisualStudio' does not exist in the
namespace 'Microsoft' (are you missing an assembly reference?)
...\packages\microsoft.net.test.sdk\16.2.0\build\netcoreapp1.0\Microsoft.NET.Test.Sdk.Program.cs
If we consume the Microsoft.NET.Test.Sdk package, when we compile and build our project, the Microsoft.NET.Test.Sdk.Program.cs will also be compiled by the csc.exe during the build.
So the error message indicates the Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode attribute can't be recognized well because something is wrong with the reference to Microsoft.TestPlatform.ObjectModel.dll.
Note:
1.Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode comes from assembly Microsoft.TestPlatform.ObjectModel.dll.
2.Microsoft.NET.Test.Sdk package depends on Microsoft.TestPlatform.TestHost package, and Microsoft.TestPlatform.TestHost package depends on Microsoft.TestPlatform.ObjectModel package.
If those packages are installed successfully, the compile and build should work. So actually I think something is wrong in your installed packages.
Some simple suggestions you can try:
1.Go Tools=>Nuget Package Manager=>Package Manager settings to make sure two options of Package Restore are enabled. And then delete the bin, obj folders and run a rebuild.
2.If #1 not works, try clean the nuget cache by UI in VS IDE, and then again delete the bin, obj folders, then run a rebuild.
3.Please update your VS IDE to latest version, 16.0.0 is too old, and latest version has fixed some issues.
Project is .NET Core 2.2 but it's using package from netcoreapp1.0
folder
If you open the package in path ...\packages\microsoft.net.test.sdk\16.2.0\build you can find this package only have three version of assemblies, net40, netcoreapp1.0 and uap10.0. Since your project is .net core 2.2, it will reference the assembly in netcoreapp1.0 folder. It's expected behavior.

Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'

Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar', in Xamarine Android . I am using Visual Studio 17.
And also
When i am intalling below package from Nuget Package Manager in Visual Studio 2017 for Xamarine.Android i am getting erorr below.
Error:
Could not install package 'Xamarin.Android.Support.v7.RecyclerView 27.0.2.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
It's probably a build issue, clean your solution, delete bin and obj folder and then rebuild, see if it persists.
You can also try restarting VS once.
If it persists you might be missing the Appcompat library, which you can install via nuget.

The type or namespace name does not exist in the namespace. .NETCore - Visual Studio 2017

I am using a mac with visual studio 2017. I'm trying to start up a project with NuGet packages inside. When I right click on the source and go to update NuGet packages, I receive incompatible errors for 15 of the packages.
Checking compatibility for System.Net.WebSockets 4.0.0 with
.NETCoreApp,Version=v1.1. Incompatible packages: 15 Package restore
failed. Rolling back package changes for 'project.api'.
When I restore packages for the solution, it works successfully. When I go to build the project I get 28 errors. All with the same text -
error CS0234: The type or namespace name '' does not exist in the
namespace 'project.api' (are you missing an assembly reference?)
This issue does not persist on a counterparts Windows machine. I have no idea what to do or where to go.
Side note - unsure where to go to the NuGet package manager then go to package manager settings. This exists on windows but not Mac it seems.
The latest version was not pushed to the repo. This was why I was getting the errors. So the build error is fixed but the update NuGet packages are still incompatible. Not going to worry about that for now.

Nuget Packager task - dependency is not added

I'm using Visual Studio Team Services to automate the creation of a nuget package. This package has a dependency on another nuget package (Newtonsoft.Json v8.0.3). I have configured a Nuget Packager task as part of the build:
But the generated package doesn't contain the reference to the nuget package:
Running the following script on my local machine to generate the package:
nuget pack myproject.csproj -Symbols -IncludeReferencedProjects -Properties Configuration=Release -OutputDirectory bin/Release
I can see that the dependency is added to the generated package:
What am I missing here? Why the dependencies are not being added to to package that is being generated on the build server?
"IncludeReferencedProjects" is used to add the referenced project to the nuget package, not the referenced nuget packages.
Include referenced projects either as dependencies or as part of the
package. If a referenced project has a corresponding nuspec file that
has the same name as the project, then that referenced project is
added as a dependency. Otherwise, the referenced project is added as
part of the package. Learn more at NuGet.org.
When you create the nuget package for the project which referenced to another nuget package. The nuget package dependency will be added automatically if the nupkg file exists in the packages folder. For your issue, you can add a "NuGet Installer" task in your build definition to restore the nuget package files for your solution. And then when you create the nuget package for your project, the referenced nuget package will be added as dependency.
I have found a solution for my problem, even though I don't understand why the package was not being created properly.
So basically I have 2 builds:
a "generic" build that will compile the entire solution and run unit tests, etc (automatic, triggered on commit)
a build to generate the nuget package (manual)
This problem is on the 2nd build. I was trying to understand what were the differences between creating the package manually on my local machine and creating the package on the build server and I realized that on the build server I was not getting the source code for the solution, only for the project folder and the .nuget folder. Given that I have more than 40 projects in the solution it makes no sense to get the whole source code for the 2nd build, right? But for some reason this is not enough to generate the nuget package properly.
So, the solution to my problem was to get the source code for the following files/folders:
Project folder
.nuget folder (needed when restoring/installing the missing packages)
Solution file (mysolution.sln)

Universal application with visual studio online

I'm currently setting up project in Visual Studio Online (VSO) and having troubles with setting up automated build.
My solution contains projects targeted as Universal Windows
VSO uses msbuild to run my project.
During build I see strange error messages like:
Error CS0518: Predefined type 'System.Void' is not defined or imported
Error CS0518: Predefined type 'System.Object' is not defined or imported
Error CS0246: The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?)
msbuild is invoked with following parameters:
C:\Program Files (x86)\MSBuild\14.0\bin\amd64\msbuild.exe "C:\a\b0d9e3fd\test\src\Shipping.sln" /nologo /m /nr:false /fl /flp:"logfile=C:\a\b0d9e3fd\test\src\Shipping.sln.log" /dl:CentralLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:Platform=Win32 /p:TargetVersion=”Windows10” /p:TargetPlatformVersion=”10.0.10010.0” /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="14.0"
What's wrong with this? Are there any other additional parameters required to build universal windows app with msbuild?
Are you targeting the Windows 10 SDK? If so note that it is not installed on the TFS hosted build servers. Consequently you will not be able to build apps that use the Windows 10 SDK. You can see the complete list of installed software here.
Just found the solution.
If build UWP app, from VS it resolves NuGet dependencies automatically. By default VS 10 projects uses NuGet of 3rd version, which was not installed on our build machine. That's why we had such issue.
The problem was fixed with installing NuGet 3 onto build agent and configure script which resolves NuGet packages before build.
If you can't customize the software of your build agent (aka: the free Hosted Agent) another work-around is to just check in your project.lock.json file.
This is because NuGet v2.8.7 can read both project.json and project.lock.json files but it cannot generate a project.lock.json file from a project.json file.
And, if at such a time Microsoft updates NuGet for their default build agents, you can just remove it from source-control and let it generated automatically as part of Nuget -restore. Until then, just check it in.

Resources