Vast Increase in build time after Upgrading from VS2015 to VS2017 - visual-studio-2017

Short Version:
Build times for a .NET solution have gone from an average of 12 minutes to 34 minutes.
Long Version:
I had a Visual Studio 2015 solution with three projects in it:
MVC web application targeting .NET 4.5
c# class library for models targeting .NET 4.5
c# class library for data access targeting .NET 4.5
The solution is being built successfully in TeamCity 2017.1.5 using an "MSBuild" build step and the MSBuild 14.0 tools. The TeamCity step has the following flags:
/p:DeployOnBuild=true /p:PublishProfile="%system.teamcity.build.workingDir%\WEBAPPLICATION\Properties\PublishProfiles\PUBLISHPROFILENAME.pubxml" /p:Configuration=CONFIGURATIONNAME /p:VisualStudioVersion=14.0 /p:AutoParameterizationWebConfigConnectionStrings=false /p:SkipExtraFilesOnServer=false /p:DeleteExistingFiles=true
This setup has enabled our continuous integration/continuous deployment for our development server. It may be important to note that locally, we do not build the MVC views, but the build configuration on TeamCity enables MVCBuildViews first thing. This results in speedier development for our team locally.
A need arose for the majority of our models project to be utilized by another .NET project. Because Microsoft deprecated Portable Class Libraries and our models project makes extensive use of the [Serializable] attribute, which is not supported by PCL without numerous changes, we made the decision to change the models project to a .NET Standard 2.0 library project. The end goal is that we will use our private NuGet server to package up this one .NET Standard 2.0 library project as a NuGet package for use in this other project.
We upgraded our development machines from Visual Studio 2015 to Visual Studio 2017, created a new .NET Standard 2.0 project within the same solution, copied all of our models from the older models project to the new project, updated all of our references in the web application and data access project, and changed the web application and data access projects to target .NET 4.6.2. The solution builds successfully locally and is working just fine.
I was able to get TeamCity to build this new version of our solution by making sure the server where the agents are installed has Visual Studio 2017 installed along with the 4.6.2 targeting pack (this part was annoying to figure out). After extensive trial and error, I was only able to get TeamCity to successfully build the solution using a batch file and calling the batch file with a command line build step.
Here is the call from TeamCity:
c:\MYBATCHFILE.bat "%system.teamcity.build.checkoutDir%" "CONFIGURATIONNAME" "PUBLISHPROFILENAME"
Here is the batch file:
"C:\Program Files\dotnet\dotnet.exe" restore %~1\NEWMODELSPROJECT
%~1\..\..\tools\nuget.commandline.4.4.0\tools\nuget.exe restore %~1
"C:\Program Files\dotnet\dotnet.exe" build %~1 /p:Configuration="Release"
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" %~1\DATAACCESSPROJECT\DATAACCESSPROJECT.csproj /p:Configuration=%~2 /p:Platform="AnyCpu" /p:VisualStudioVersion=15.0
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" %~1\WEBAPPLICATION\WEBAPPLICATION.csproj /p:Configuration=%~2 /p:Platform="AnyCpu" /p:VisualStudioVersion=15.0 /p:DeployOnBuild=true /p:PublishProfile=%~1\WEBAPPLICATION\Properties\PublishProfiles\%~3.pubxml /p:AutoParameterizationWebConfigConnectionStrings=false /p:SkipExtraFilesOnServer=false /p:DeleteExistingFiles=true
Essentially, we use dotnet restore on the .NET Standard 2.0 project, NuGet restore on the rest of the solution, dotnet build the .NET Standard 2.0 project, and then MSBuild the other two projects in the solution with the MSBuild 15.0 tools and the same flags as we were using before.
We aren't seeing any issue with the solution locally, but within TeamCity, our average build time has skyrocketed from 12 minutes to 34 minutes. It is important to note that no other major change has occurred with the project during this upgrade. The biggest time sink, by far, is MvcBuildViews. Here is a highly redacted version of the build log, as taken from TeamCity:
[10:50:07] The build is removed from the queue to be prepared for the start
...
//all other steps of the build complete in this amount of time
...
[10:50:21] Step 8/15: Run Batch (Command Line) (33m:28s)
...
//the other portions of the above batch file run in this time period
...
[10:51:15] MvcBuildViews:
...
[11:23:50]
[11:23:50] 104 Warning(s)
[11:23:50] 0 Error(s)
[11:23:50]
[11:23:50] Time Elapsed 00:33:16.53
[11:23:50] Process exited with code 0
...
//minor clean up steps
...
[11:23:53] Build finished
These average times are the same whether the batch file is run by TeamCity or manually from the command line. So, to put it bluntly, what has happened between MSBuild 14.0 and MSBuild 15.0 that the MVCBuildViews task takes 3 times longer? Are there flags or options I can pass to MVCBuildViews to improve this build time?

Related

Building and running unit tests with Visual Studio build tools

I am adding unit tests to an existing C++ Visual Studio projects, using the Google Test adapter.
It's all running fine on my computer with Visual Studio 2019, but when I try to run them on the build server I get the following error
error : 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 ..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets.
However, we're not using NuGet for package management. I tried installing it but complained about missing folders. This is not a .NET project, so I think that's a red herring.
I was able to install the Google Test adapter on my computer using the Visual Studio Installer, but it does not show up as a part of the VS Build Tools on the build server.
Running msbuild -t:restore does not help, it just reports "nothing to do."
I don't understand why the Google Test adapter isn't available for VS Build Tools, since it seems to be required in order to build the unit tests. Does anyone know why it doesn't work? What's the best practice for handling this?
Thanks!
The problem is that your c++ project has missed the content of googletest nuget package. So the solution is to restore the whole nuget package in your c++ project.
Update 1
First of all, take a brand new backed up project and restore it to when the problem started.
Besides, msbuild -t:restore command applies to projects with PackageReference nuget management format.
Since your c++ project used packages.config nuget management format, msbuild -t:restore will not work. See this official document.Instead, you should use nuget restore command.
This command works for your current project and running this command will restore the nuget packages and then you will never face the issue.
Before using it, you should download nuget.exe CLI and config its path into System Environment Variable PATH so that CMD can invoke nuget.
The steps about configing nuget.exe, you can refer to this link.
Steps
1) delete packages folder under the solution folder
2)Then, open build tool, run:
nuget restore xxx\xxx\xxx.sln(the full path of solution file containing the c++ project and the unit test project)
Then, you can build the project with the command. And I hope the error will disappear.

Visual Studio installer fails on AspNetDiagnosticPack.msi

I have the problem described here.
Any attempt to install AspNetDiagnosticPack.msi
C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.VisualStudio.AspNetDiagnosticPack.Msi,version=15.0.40314.0\AspNetDiagnosticPack.msi fails with error status: 1603.
I cannot add or remove any component using VS installer now.
I have installed VS 2017 Professional as follows:
Microsoft Visual Studio Professional 2017
Version 15.6.6
VisualStudio.15.Release/15.6.6+27428.2037
Microsoft .NET Framework
Version 4.7.02558
Installed Version: Professional
Visual C++ 2017 00370-20001-54960-AA753
Microsoft Visual C++ 2017
Visual F# Tools 10.1 for F# 4.1 00370-20001-54960-AA753
Microsoft Visual F# Tools 10.1 for F# 4.1
Application Insights Tools for Visual Studio Package 8.11.10402.2
Application Insights Tools for Visual Studio
ASP.NET and Web Tools 2017 15.0.40314.0
ASP.NET and Web Tools 2017
Azure App Service Tools v3.0.0 15.0.40215.0
Azure App Service Tools v3.0.0
C# Tools 2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Cookiecutter 15.6.18072.2
Provides tools for finding, instantiating and customizing templates in cookiecutter format.
Dotfuscator Community Edition 5.32.1.6167-6ce295ebd
PreEmptive Protection - Dotfuscator CE
JavaScript Language Service 2.0
JavaScript Language Service
JavaScript Project System 2.0
JavaScript Project System
Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51212.2
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards
Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package
Node.js Tools 1.4.11027.3
Adds support for developing and debugging Node.js apps in Visual Studio
NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
Python 15.6.18072.2
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.
Python - Django support 15.6.18072.2
Provides templates and integration for the Django web framework.
Python - IronPython support 15.6.18072.2
Provides templates and integration for IronPython-based projects.
Python - Profiling support 15.6.18072.2
Profiling support for Python projects.
SQL Server Data Tools 15.1.61801.210
Microsoft SQL Server Data Tools
TypeScript Tools 15.6.20202.3
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
I thought that the problem originated in having some remains from previous VS editions. I could not uninstall namely ASP.NET and Web Tools 2013.1. I have finally removed it after all by reinstalling VS 2015 and using the FixIt tool from this answer.. But still AspNetDiagnosticPack.msi fails the same way.
I also tried to uninstall the web development role completely, since I will probably not use it soon, but installation allways fails. Is there any workaround to make the VS installer work again?
The msi log is here.
Action 15:50:02: WebConfigInitialize.
Action start 15:50:02: WebConfigInitialize.
MSI (s) (B8:F4) [15:50:02:244]: Invoking remote custom action. DLL: C:\Windows\Installer\MSIFF27.tmp, Entrypoint: Initialize
MSI (s) (B8:40) [15:50:02:244]: Generating random cookie.
MSI (s) (B8:40) [15:50:02:244]: Created Custom Action Server with PID 10588 (0x295C).
MSI (s) (B8:14) [15:50:02:306]: Running as a service.
MSI (s) (B8:14) [15:50:02:306]: Hello, I'm your 32bit Impersonated custom action server.
SFXCA: Failed to create new CA process via RUNDLL32. Error code: 2
CustomAction WebConfigInitialize returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 15:50:02: WebConfigInitialize. Return value 3.
But the problem is within custom action WebConfigInitialize and the log is no big help. I have observed that there was an entry Microsoft ASP.NET and Web Tools 2015.1 - Visual Studio 2015 when I ran the uninstaller tool - and this entry failed uninstalling. Perhaps the origin of my problems is that I once installed some beta verison of ASP.NET with Visual Studio 2015. I do not need ASP.NET for now, but I the VS 2017 installer is stuck on the error.
I have found WebToolsExtensionsVS14_rc2_48.msi in cached packages on my computer and uninstalling this package fails the same way with 1603 as the 2017 current package.
Action 8:30:41: WebConfigInitialize.
Action start 8:30:42: WebConfigInitialize.
MSI (s) (48:BC) [08:30:42:012]: Creating MSIHANDLE (550) of type 790542 for thread 1980
MSI (s) (48:F0) [08:30:42:012]: Invoking remote custom action. DLL: C:\Windows\Installer\MSIA2E1.tmp, Entrypoint: Initialize
MSI (s) (48!A0) [08:30:42:028]: Creating MSIHANDLE (551) of type 790531 for thread 928
SFXCA: Failed to create new CA process via RUNDLL32. Error code: 2
MSI (s) (48!A0) [08:30:42:028]: Closing MSIHANDLE (551) of type 790531 for thread 928
CustomAction WebConfigInitialize returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (48:F0) [08:30:42:028]: Closing MSIHANDLE (550) of type 790542 for thread 1980
Action ended 8:30:42: WebConfigInitialize. Return value 3.
Similar problem here, that one ended with reninstalling his machine.
Or is there some tool that would show the dependencies of a particular MSI package?
The Developer's community link that is current and relevant to the problem is here.
It says:
We have fixed the problem in an upcoming release. We've addressed the
managed custom action in the ASP.NET Diagnostic Pack that modifies the
root web.config file to use a native code action. This should avoid
the CLR errors previously reported when it tried to launch the managed
code DLL during the install.
The fix for this is now in our latest Visual Studio Preview release.
If you'd like to try out the fix, you can access the preview build
here: https://www.visualstudio.com/vs/preview
Looks like there is no workaround except waiting for Microsoft's fix to that faliling custom action. I have ignored this recommendation at first because I did not check the date of comments properly but they are only one month old.
But when I have tried to install the preview it ended with exactly the same error.
In 15.7.1 version the same error again.
UPDATE: It looks like the issue might be a managed code custom action failing in the MSI in question (.NET code that can't run - for whatever reason 1, 2, 3).
Suggestion
I would first try to 1) do the reboot I recommend below - to clear the air and release any locks - then 2) disable security software / anti-virus and 3) try the install and enable logging as described below.
Core Deployment Problems
As deployment goes, problems tend to center around: 1) something is locked (in use - by other processes or other users logged on), 2) something is blocked (access / permissions denied), 3) dependencies are missing for your custom actions or the whole installer (runtime requirements not satisfied - for example missing .NET runtime version), 4) something is corrupted (data file, OS settings, malware is often the culprit here - or unwise tinkering), 5) there is an unexpected system state such as the disk being full, or more exotic the date and time is wrong, or there is a licensing issue or some other oddity, etc...
That is a very simplified list of causes - there are obviously many further issues, for example 6) localization errors: hard coded paths, erroneous parsing of dates and time, invalid characters in path names, etc... 7) file and path names are too long, 8) and the Microsoft specialty: weird and unexpected incompatibilities between products not thought to have a valid reason to conflict with each other (different versions of Visual Studio, etc...), etc..., but that is going way too far for your problem. Still, here is a generic "deployment problems" summary from some time back - just for reference.
Procedure
Reboot: The first thing I would do is to reboot and then try to invoke the install the regular way. This is just to rule out this "simple solution" (which sometimes works). There could be files in use that the installer must replace in order to complete.
Logging: In order to maximize the available debugging information you could log the install with verbose logging and debugging information (if you have access to the MSI itself).
Open an elevated command prompt (right click and run as administrator)
Change current directory (cd) until you get to: C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.VisualStudio.AspNetDiagnosticPack.Msi,version=15.0.40314.0\
MSI Log: Run this command (adjusting paths as appropriate - especially for the log file): msiexec.exe /i AspNetDiagnosticPack.msi /L*vx C:\Test.log
Enable All: You can enable logging for all MSI files (slows installs, but great for advanced users): http://www.installsite.org/pages/en/msifaq/a/1022.htm (section: "Globally for all setups on a machine")
Interpret: How to interpret an MSI log file: http://www.installsite.org/pages/en/msifaq/a/1045.htm
Event Log: You can also have a look in the event log. Rather than repeating the procedure here, I will link to a similar, recent answer.
Different User: This is unusual advice (and I haven't tried it), but sometimes you can succeed with difficult installs by creating a new local admin user on the machine, and then running the installer from there. It has to do with errors in the user profile. Not the first thing to try, but adding it as an option.
I tried to uninstall VS 2019(!) and I faced the same problem (I cannot add or remove any component using VS installer).
It hang for a long time and finally throwed an error at "AspNetDiagnosticPack.msi".
I found a solution that led me also to
%programdata%Microsoft\VisualStudio\Packages\Microsoft.VisualStudio.AspNetDiagnosticPack.Msi,version=16.3.283.64955
I simply ran the msi stand alone. During the process I was asked to do kind of clean up for an outstanding installation issue.
After that I ran the uninstall ( And later the reinstallation ) of VS 2019 again and it worked.
Maybe this solution helps you along with VS 2017

Can't get XUnit tests working with Visual Studio 2017 RC

For the life of me I can't get unit testing working in Visual Studio 2017 from the new msbuild-based netcoreapp1.0 xunit project template.
The requirement is for unit tests to work both inside Visual Studio (for the devs) and from dotnet test on the CLI for the automated build process however, I can't get either working consistently.
Here is what I have tried:
In an existing solution, create a new project and select .NET Core > xUnit Test Project.
Build project from Visual Studio, default test appears and runs successfully, now run dotnet test from powershell prompt, get:
> dotnet test
Test run for D:\...\bin\Debug\netcoreapp1.0\MyProj.dll(.NETCoreApp,Version=v1.0)
dotnet exec needs a managed .dll or .exe extension. The application specified was 'C:\Program'
Or dotnet test with csproj file:
> dotnet test MyProject.csproj
(same error as above)
> dotnet test ..\MySolution.sln
Couldn't find a project to run test from. Ensure a project exists in D:\...
Or pass the path to the project
If I add the xunit.runner.console or xunit.runner.msbuild nuget packages, it stops the unit tests working from inside Visual Studio.
How do I get both working at the same time?
Thanks!
The bug you're hitting is present in Preview 3 and fixed in Preview 4. They didn't escape the command line when executing it, and since dotnet.exe is installed into C:\Program Files\dotnet by default, it always fails.
If you want to continue to use Preview 3, the simplest work-around is to edit your system PATH environment variable, and replace C:\Program Files\dotnet with C:\Progra~1\dotnet.
I know this isn't a very good answer, but dotnet-test-xunit only support project.json files. VS 2017 forces you to switch to csproj files.
I found this on xunit twitter feed:
If you're trying use #xunit in VS2017 RC w/ .NET Core, remove dotnet-test-xunit and use xunit.runner.visualstudio 2.2 beta 4 instead.
With the latest RC.3 I was having issues with the tests not being discovered, and found out that when you run the built-in Test Explorer it says in the output that Microsoft.DotNet.InternalAbstractions 1.0.0 is missing. This was also issue in the previous versions of .NET Core, and the solution is the same, install the package from Nuget.

How to build on TFS a c++ native project targeting Win10 platform

A migrated VS2013 c++ native project to vs2015 targeting Windows 10 (instead of Win 8.1) gives me some issues on the TFS Build Server. I use TFS2013 and the Release12 Build Process Template.
The TFS2013 is installed on a Win10 machine with VS2015 installed on it.
When I run the build the build throws an exception in one of the tasks from the target files saying that it can't compare the numeric number 10.0.4 ... something, because that is the Target Platform set in the native project file. Obviously this is not a number with it's two dots in the version number.
Am I doing something wrong? The TF Build uses MS Build v12 by the way and not the MS Build v14 that ships with VS2015. Do I need to change to MSBuild v14 to make this work? If yes, how can I actually change the used MSBuild version?
Can you provide more information about your exception and build file?
I'm not sure is it realed to MSBuild V14.
If You want to amend the build templates to point to MS Build version 14.0. You can folow below steps :
Use the Default Template (TfvcTemplate.12.xaml) in Visual Studio
Open the template and find the Run MSBuild for Project MSBuild activity.
Set ToolVersion to "14.0".
Set ToolPath to target to MSBuild14 (by default: "C:\Program Files (x86)\MSBuild\14.0\Bin").
Check in this build process template and re-queue the build.
If you still have the same problem after you use MSBuild V14.0.
There is a realted version with 10.0.4... in VS2015. MinimumVisualStudioVersion = 10.0.40219.1 .It means the minimum visual studio version supported in VS2015. Maybe you build a file that created by a visual studio which version is earlier than the version10.0.40219.

What do I need to install for C++ project / VS 2013 on TeamCity server or Team Foundation Build Service?

I am attempting to build a C++ project in a Visual Studio 2013 solution on TC 8.0.6 (build 27767).
I have installed the latest MSBuild "Microsoft Build Tools 2013" stuff (which is normally installed as part of VS 2013 install) directly on the server.
But I get the following error:
[17:05:23]VCTargetsPath is c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\
[17:05:23]PlatformToolset is v120
[17:05:23]VCMessage
[17:05:23]c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32
Microsoft.Cpp.Win32.Targets(512, 5): error MSB8008: Specified platform toolset (v120) is not installed or invalid. Please make sure that a supported PlatformToolset value is selected.
[17:05:23]Project MyCppProject\smCpp.vcxproj failed
As far as I can see I have everything I need and I have tried various hacks to set the PlatformToolset to v110 etc., but that doesn't work either.
At this stage I would like to verify exactly what I need to install on the build server. Can someone clarify if I need anything extra please?
Many thanks
Brian
Ultimately you need to set the correct path to MSBuild. With VS 2013, build tooling became part of VS rather than .NET, making it version 12.0 instead of 4.0. The default path in this instance is:
"C:\Program Files (x86)\MSBuild\12.0\bin"
If the team foundation build is broken then it's likely because the TF server is not on version 2013. To fix the problem you need to make yourself a copy of the build template the build definition uses (assuming your version is >= 2010 and < 2013) and point to the correct tooling folder. The build templates are located in the following source path:
$/YourTeamProjectName/BuildProcessTemplates
If you can edit the template in Visual Studio you open the Workflow Foundation design surface. In there find the Run MSBuild for Project tasks (note in the default template there is more than one, but I've shown a pic of what to look for) and change the tool path property to the above path.
Once you created the template you need to change your build definition to use the new template.
For TeamCity you need to set the MSBuild ToolsVersion to version 12.0 in your build step. I'm not sure what version of TC started support for version 12.