CICD TFS 2013 - Nuget auto restore on TFS Serer build - tfs

CICD TFS 2013 - Nuget auto restores on TFS Serer MSbuild(not in Visual Studio):
I added NuGet.config file on a solution folder. but auto restores NuGet on TFS Build it's not worked.
Error:
enter image description here
$/Core/testCICD/Webtest/Webtest.sln - 5 error(s), 1 warning(s), View Log File
Default.aspx.cs (8): The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Default.aspx.cs (9): The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Model\Account.cs (1): The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Model\Account.cs (12): The type or namespace name 'JsonProperty' could not be found (are you missing a using directive or an assembly reference?)
Model\Account.cs (12): The type or namespace name 'JsonPropertyAttribute' could not be found (are you missing a using directive or an assembly reference?)
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, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

CICD TFS 2013 - Nuget auto restore on TFS Serer build
According to the error message, it shows you have use the Newtonsoft.Json, Version=12.0.0.0 in your project.
AFAIK, starting from Newtonsoft.Json 9.0.1, this package supports the targets framework .NETStandard:
https://www.nuget.org/packages/Newtonsoft.Json/9.0.1:
Which is supported by NuGet 2.12.
So, to resolve this issue, you should make sure the nuget.exe version is higher than 2.12 and the Visual Studio version is high than 2013.
To resolve this issue, you could update Visual Studio 2013 to Visual Studio 2015 and above, then use MSBuild task to specify the MSBuild 14.0 (or above) to build your project.
Or you could use the Newtonsoft.Json 8.0.3 instead of 12.0.x in your projects.

Related

Problem Setting up a build in azure devops for mvc appliaction(The type or namespace name 'mvc' could not be found)

I have a mvc3 application in. net framework 4.7.2.
This is a solution that was upgraded from mvc2 and build with out issue in visual studio 2019.
I do not have any nuget package.
My source code is in git azure devops.
I try to create a asp.net build in azure devops and I receive the following errors
List item Error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Error CS0246: The type or namespace name 'HtmlHelper' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246: The type or namespace name 'UrlHelper' could not be found (are you missing a using directive or an assembly reference?)**
Please note I have system.web.mvc and system.web.webpages added to my references in MVC project and it complies ok in Visual Studio 2019.
here is content of my yml file:
You need to first restore NuGet packages so please enable these steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
I figured out the issue . I did not have any package.config in my solution . I added that and installed asp.net MVC package and it works now

Error CS0234: The type or namespace name 'Azure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) in TFS build

I have updated our ASP.NET Web API solution to include the Microsoft.Azure.NotificationHubs Nuget package as I want to be able to send push notifications to our mobile clients. I have written a new controller that does this. Everything works fine.
When I check-in the code changes to our on-premise TFS build server I am getting the error:
Error CS0234: The type or namespace name 'Azure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
I have updated the build server to the latest VS2017 build tools but am still getting the error. I can't determine if this is an MSBUILD or VS error.
I am using Visual Studio 2017 15.9.4. The project uses .NET Framework 4.6.1.
UPDATE
After some further investigation I can see that the TFS build server is NOT restoring the Nuget package for Microsoft.Azure.NotificationHubs but restores all the other Nuget packages. So the problem seems to be due to the Nuget package not being restored during the build
Here is a screenshot showing that the package.config correctly references the nuget package. But for some reason this nuget package is NOT getting restored during the build.
I've eventually managed to fix this by adding a commandline nuget restore task to the build pipeline.
NuGet.exe restore MySolution.sln
I resolved it by uninstalling and installing the nuget package back again.

Visual Studio 2015 New .NET MVC Project Error: "Index (zero based) must be greater than or equal to zero..."

Question: How do I create a new project without this (authentication-related) error?
Symptoms: The new (completely unaltered) project does not build (see Build Errors image).
Error replication steps:
Open Visual Studio (my version = 2015)
File
New
Project (see Project image for settings)
OK
Error (see Error image for alert)
OK
Build
Build Errors (see Build Errors image)
Note: the error only appears when authentication is included in the new project and appears to be related to authentication because I receive several warnings and errors concerning authentication-related dependencies (see Dependencies image for warnings).
I've tried...
Closing and re-opening Visual Studio
Uninstalling and re-installing Visual Studio
Project
Error
Dependencies
Build Errors
Some errors (if the image is hard to read)
CS0246 The type or namespace name 'SignInManager' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'OwinStartupAttribute' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'IdentityUser' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'IAuthenticationManager' could not be found (are you missing a using directive or an assembly reference?)
The screenshots you attached are clearly showing that you have broken references for asp.net identity framework.
You can try removing those references and install the nuget package again.
Here is the package name : Microsoft.AspNet.Identity.Owin
https://www.nuget.org/packages/Microsoft.AspNet.Identity.Owin/

Compile errors after installing VS2015

I was working on VS2013 on a class library project that references MVC dll from the following location:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll
Then I uninstalled VS2013 then installed VS2015. Now my project is demanding the MVC dll
Please note that the following path:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\
is missing from my computer.
The following compile error appears on build:
Severity Code Description Project File Line
Error CS0234 The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
My guess would be that MVC4 was bundled together with visual studio 2013 and thus is also removed. You could try to reinstall it yourself using the web platform installer or removing the dependencies and re-adding them using nuget (https://www.nuget.org/packages/Microsoft.AspNet.Mvc/4.0.40804) Install-Package Microsoft.AspNet.Mvc -Version 4.0.40804

How can I get MSBuild to build my solution using MVC assemblies that are referenced as nuget packages

I am trying to get an MVC solution to build on a test server without having visual studio or MVC 4 installed on the machine.
The solution refers to all the required MVC assemblies as nuget packages. In the projects all of the MVC assemblies are marked as copy local. Of course, on my dev machine the solution builds fine in visual studio.
On the build machine I have installed the .net sdk and I am trying to use MSBuild to build the solution. All of the nuget packages are under source control and when I do an SVN update on the server it gets all of the packages.
When I run the build I am getting a broken reference to the MVC DLLs. I don't get why this is happening since in the solution the DLLs are referenced and are present for the build to use.
Here is a sample of the error returned by MSBuild...
DataAnnotations\RunDataAnnotationsFromModelPropertyAttribute.cs(5,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
DataAnnotations\RunDataAnnotationsFromModelPropertyAttribute.cs(12,93): error CS0246: The type or namespace name 'IClientValidatable' could not be found (are you missing a using directive or an assembly reference?)
Security\MyAuthenticateAttribute.cs(6,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Security\MyAuthenticateAttribute.cs(12,48): error CS0246: The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)
Security\MyAuthorizeAttribute.cs(5,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Security\MyAuthorizeAttribute.cs(13,45): error CS0246: The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)
Web\Mvc\MyLoginController.cs(7,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Web\Mvc\MyLoginController.cs(44,62): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) ...
I have spend hours on this. It frustrates me that it builds in visual studio on my machine but not on the server using msbuild.
Seth
Right click on the project and click "Unload" and then again and click "Edit".
Find the <Reference> for System.Web.Mvc. If the <HintPath> doesn't refer to the "packages" directory (or is missing), then that's your problem. Just remove the package and all references and start again.
NuGet package restore only restores the files on disk, it doesn't update the project references.
"Copy local" just means it'll copy the assemblies from your MVC3 installation which you haven't installed on your remote machine.
Did you try to copy the MVC dlls to a folder (which you commit to your VCS repository) in your project and reference all of them from there instead from the default installation directory?? That should work just fine.
Try running nuget install on the solution prior to running your msbuild command? If you are running VS2010 or later and have updated the nuget extension to the latest version, there is an option on the Project menu to "Enable Nuget Package Restore." This will configure your solution and project files to that they run nuget install as part of the build process.

Resources