Visual Studio Team Services build fails because CoreCompile does not reference NuGet assembly - visual-studio-2017

I am running into an weird issue where my build works perfectly on local machine but almost always fails on Visual Studio Team Services build agent. I say almost always the same code sometimes builds fine on VSTS build agent.
The error is that for a project in my solution, the compiler could not find System.Web.Http.dll, which is referenced in Microsoft.AspNet.WebApi.Core NuGet package. I've checked the reference and it is there. I've removed the NuGet and re-added it to fix any potential NuGet hiccup.
The exact error is this:
Error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
The reference is in the csproj file:
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\Microsoft.AspNet.Cors.5.2.3\lib\net45\System.Web.Cors.dll</HintPath>
</Reference>
The NuGet restore task from VSTS suggested that all NuGet packages were installed, but the build still failed.
I then did a diff between the command lines of the successful build and failed build, both from Visual Studio Team Services build agent and found that the failed build CoreCompile task was missing some assembly references.
CoreCompile gets the assemblies to reference from ResolveAssemblyReferences. But ResolveAssemblyReferences claims that it could not find System.Web.Http.dll.
For SearchPath "{HintPathFromItem}".
Considered "....\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll", but it didn't exist.
Is there any known issue with NuGet restore from VSO? We are using NuGet 4.0.
UPDATE:
Visual Studio Team Services support came back to me. I had my own nuget.config which had the following 2 lines. This interfered with the global NuGet cache on the build agents. Once I removed these 2 lines everything went smoothly as expected.
<add key="globalPackagesFolder" value="..\nupkgs" />
<add key="PackageSaveMode" value="nuspec" />

It looks like, at some point, this reference was added manually, and the relative paths match up on your local PC.
In every valid nuget reference I've seen, those relative paths are prefixed with "packages". Try deleting the nuget package, and delete this reference, then reinstall it.

Here is the answer to the issue I ran into.
Visual Studio Team Services support came back to me. I had my own nuget.config which had the following 2 lines. This interfered with the global NuGet cache on build agents. Once I removed these 2 lines everything went smoothly as expected.
<add key="globalPackagesFolder" value="..\nupkgs" />
<add key="PackageSaveMode" value="nuspec" />

Related

Missing file NuGet.targets on existing project

The scenario is:
1. Created a NEW solution
2. ENABLED download missing packages
3. Add projects to solution that already exists and depends on nuget packages
4. Building the solution generates an error:
... The missing file is <solution folder>\.nuget\NuGet.targets.
Why? Have missing something?
I'm using Visual Studio 2017 Pro on Windows 10
All my searches answer about the scenario where create a new solution and adds a new project that depends on nuget package, that's ok, but when have an existing project, nothing.
<solution folder>\.nuget\NuGet.targets is a file that NuGet's Visual Studio extension used to add in Visual Studio 2010, 2012 and 2013 when you right click on the solution and select "Enable NuGet Package Restore". It would then add an import in all of your project files to import the targets file. I was recently investigating a customer issue and as part of that investigation I found it made the following changes. Near the top of the csproj, it adds something like this:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
and near the end of the csproj it adds somthing like this:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<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>
So, the problem is that you're creating a new solution, but using existing project files that have been modified in this way. One option is to edit your csrpoj files and remove these changes. Another option is to create new projects, in addition to the new solution, and then copy all your code and content files.
The only disadvantage is if you build on a CI server and use packages.config, your build script needs to run nuget.exe restore, whereas projects that use NuGet.targets could just build the solution and msbuild would execute nuget restore as needed. One advantage of no longer using NuGet.targets is that restoring the whole solution is faster than restoring project by project. Visual Studio automatically restores packages on build, even in VS2010, VS2012 and VS2013, so personally I discourage the use of using this feature, even if you use those old versions of Visual Studio. The benefit of reducing your build script by one step is not worth the issues it brings, in my opinion.

The target "GatherAllFilesToPublish" does not exist in the project

I've checked that the same error occurred in the past with earlier vs .net versions but I am facing this issue in VS 2017 while trying to upgrade from VS Community 15.3.5 to 15.4.
I first installed using the web installer by choosing the options,
some how there were a couple of errors & the download + installation took over 9+ hours
visual studio was working and compiling project except that this had the problem 'The target "GatherAllFilesToPublish" does not exist in the project'.
Then I tried downloading the entire setup using "vs_community.exe --layout "C:\MyFolder" --lang en-US" which again took over 9 hours to finish download. Re-ran the setup choosing Repair, again the same issue.
Is any one aware of a quicker way to solve this above problem?
I had similar problem and it solved by changing csproj file:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
changed to
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" Condition="true" />
I had same issue (Visual Studio 2017).
Install - " MSBuild.Microsoft.VisualStudio.Web.targets " nuget package to visual studio. And then try to publish.
Just install the ASP.Net Web Deployment component for VS2017, it worked for me.
Similar issue occurred with me after I upgraded project from previous version to VS 2017. I had to make following changes in the csproj file.
Uncomment the following part of code from csproj file ( It was already present as comment, not sure why it did not change while upgrade automatically. If you do not have it, add below lines of code.)
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
</VSToolsPath>
</PropertyGroup>
Make sure below 3 imports are present in the csproj file. (These were also present, but if not, add manually)
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
And then I was able to publish the project.
I wonder what packages are changing these paths?
Mine is as follows:
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildProgramFiles32)\MSBuild\Microsoft\VisualStudio\v14.0</VSToolsPath>
changed to
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
same issue as this: https://stackoverflow.com/a/48545538/231821
I had this same problem, I updated Visual Studio 2017 to a newer version via the installer.
The installer never completed successfully. It completed with some errors which I just ignored so many of the components weren't installed which came after the components with errors. After I resolved the error components, the rest of the installation finally completed successfully and I could publish again with no problems.
I think some of the components which wasn't installed previously was older versions which was not compatible with the new update.
Try installing/updating your visual studio completely with no errors.

NuGet packages not restore in visual studio 2017

I have Asp.netCore solution which was working fine on Visual Studio 2015 and then i moved to Visual Studio 2017. Now the problem is that in Visual Studio 2017 on every nuget packages there is yellow exclamation mark. Following are solution which i have tried so far.
I'm using Visual Studio Version: 15.3.1
Run as 'Administrator' and restore package.
Clear All Nugget Cache(s) from Tools > options > NuGet Package Manager > and again restore Nuget.
Note: I have searched and found following solution and tried but did not resolve my issue.
Solution 1
I found the answer on another thread here and credit should go to #AxelWass although he did not specifically focus it towards this, it absolutely fixes this issue. The above answer did not.
I had the same issue and solve it by opening the project in a text editor and deleting the following section:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
Once this is removed, it will resolve this nightmare issue that VS2017 and PM seems to be unable to resolve. I too have run into this multiple times - especially when I blend many projects in the same solutions directory.
As mentioned in Microsoft Installing and reinstalling packages with package restore Documentation, you should Update-Package -reinstall:
Update-Package -reinstall -ProjectName <project> command where
is the name of the affected project as it appears in
Solution Explorer. Use Update-Package -reinstall by itself to restore
all packages in the solution.
If you still have the error, try edit your project file, check if there is A path refrence error there, also check the project/solution nuget config file.
By default, new installation of visual studio did not configure package source to search packages online. That caused the problem.
I found the answer with a little bit more work from a stackoverflow link: https://stackoverflow.com/a/32360953/1503372.
That answer mentions to use "https://www.nuget.org/api/v2" url to restore packages. When I opened the package manager console in visual studio 2017, I found it was searching for packages from my PC only (offline search).
I then added "https://www.nuget.org/api/v2" url as a source for restoring packages and it worked.
Follow below steps to add a package source.
Right click project > Manage nuget package and you will see "package source label".
Add highlighted URL to package source.
Select "All" as package source.
Once you have configured your visual studio to search for packages online, your all packages will be restored.
I discovered a wrong configuration in the nuget.config. I don't know why, in this file there are some exclusion for my current project.
You can see your global configuration running this command in File Explorer
%AppData%\NuGet\NuGet.Config

Visual Studio 15 Compilation Fails- clean project

I am using Visual Studio 15 Preview 3
When I create a new project (ASP.Net 5 "Empty" project) and press build all it fails to build. I get the following errors.
Severity Code Description Project File Line Suppression State
Error MSB4063 The "VsTsc" task could not be initialized with its input parameters. WebApplication3 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\TypeScript\Microsoft.TypeScript.targets 247
Error MSB4064 The "OutputLogFile" parameter is not supported by the "VsTsc" task. Verify the parameter exists on the task, and it is a settable public instance property. WebApplication3 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\TypeScript\Microsoft.TypeScript.targets 261
Any suggestions please. I have added no code, just created the project and pressed build.
If you check out the Output window contents after the build has failed, it should show the targets file path like this one:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets
Go ahead and remove the OutputLogFile attribute from the VsTsc element. This should make the build go through.
Downgrading "Microsoft.TypeScript.MSBuild" from version 2.0.6 to 1.8.11 removed the Compilation Errors.
I had a similar issue. As it turns out the VsTsc task does support OutputLogFile. When I installed the newer TypeScript nuget packages (Microsoft.TypeScript.Compiler and Microsoft.TypeScript.MSBuild) then it adds Microsoft.TypeScript.targets to the .csproj but neglects to remove the previous lines. Nuget will add lines similar to
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.props')" />
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.1.4\build\Microsoft.TypeScript.MSBuild.targets')" />
You have to manually removed the two lines pointing to :
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
The same errors were observed after installing Visual Studio Preview. Visual Studio 2015 Community addition Update 3 installed on the same computer also started getting the same errors, on a number of different Typescript solutions. I could build the same solutions on an old computer 'Visual Studio 2015 Community addition Update 1'. I then uninstall Visual Studio Preview. Errors still occurred on Visual Studio 2015 Community addition Update 3. Also then uninstalled and reinstalled community addition and the problem was resolved, and could build the project. I thought this solution may help others with the problem solving a more elegant solution I do not have the reputation points to make a comment (where this belongs).
I was having the same issue with VS2015 Community and downloading the latest version of TypeScript (Version 2.1.5 posted 1/11/17) at https://www.microsoft.com/en-us/download/details.aspx?id=48593 did the trick for me.
I had the same problem. TypeScript tools in VisualStudio 2015 and TypeScript packages attached to project had different versions that is why build failed with "The "VsTsc" task could not be initialized with its input parameters". I reinstalled TypeScript tools for VisualStudio 2015 (get older vertion) it solved my problem.
I had a similar problem.
For me the solution was:
Remove "Microsoft.TypeScript.Compiler" package
Remove "Microsoft.TypeScript.MSBuild" package
from installed packages.

Type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft'

I can see from here, that the namespace Visual Studio should exist within namespace Microsoft, yet I get that error and none of my tests are working!
The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
I am using Visual Studio 2012 with Windows 8.1 (all updated).
I got this error when trying to build a project in TFS. These steps fixed it:
remove reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework
add nuget MSTest.TestFramework
add nuget MSTest.TestAdapter (optional but needed to run tests inside Visual Studio)
The above steps caused this element to be removed from my .csproj file:
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
And these two were added instead:
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
If you're using VS 2017, simply don't put the original project and the test project in the same folder. This will solve the conflict.
The namespace Microsoft.VisualStudio... is defined in assemblies which are not part of the standard Installation of Visual Studio. It is available only if you installed the Visual Studio SDK.
The MSDN Reference to the SDK and included namespaces can be found here.
After installing the SDK add a reference to the required assemblies to your project as described here.
EDIT: Please also check your Visual Studio Version. In the MSDN Link you have posted it says:
You can customize some aspects of Visual Studio Ultimate or Visual Studio Premium to extend existing features or to add new capabilities if you have special requirements. The API reference provides information about the classes to help you with your customization.
If you have one of these Versions, open your unit test project, right click on 'References' -> Choose 'Add Reference' -> Click on 'Assemblies' on the top left and search in the List for 'Microsoft.VisualStudio.TestTools.UnitTesting' (Its either in the 'Framework' or in the 'Extensions' section which you can also choose on the left). You do not need to know the actual location of the dll.
For VS 2017, I had to change the Target Framework in Properties
Ok I found out what the issue was. I had all the solution files in a different place than the usual default.
I had them in a Dropbox folder hoping that I can work on the solution from multiple computers, but apparently that was the cause of the issue.
Moving the whole solution to the default My Documents/VS 2012/Projects/ fixed the problem for me!
In short, if you want things to work smoothly, have the solution files in the usual place, unless you're an advanced user and know what you're doing (I'm not).
I suggest avoid using the "Add reference", it took me some time but I came across this NuGet that has everything that is needed for CodedUITests.
https://www.nuget.org/packages/CodedUIDependencies/1.0.0
Copy Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll somewhere into the root folder of project. When later you will be building test project in console or otherwise, copy it back to debug\bin.
If a project has no reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework I have experienced problems launching tests from Visual Studio UI -> glitches.
I got this error after installing the NuGet Microsoft.JavaScript.UnitTest. After uninstall it worked.
https://www.nuget.org/packages/Microsoft.JavaScript.UnitTest/
In my case, I had an invalid private package source. Because of this, I could not install any package at all (of course). Removing the invalid package source also allowed Visual Studio to install the packages correctly.