MSBuild Running Slow Called from PowerShell Script (Visual Studio 2019) - powershell

I set up a new TFS Build Server recently and I'm investigating some extended time periods during the build process. One of those periods is the recompiling of our Selenium test .dll. First, the packages are restored via MSBuild, which is fine. Then, the script hangs for about 10 minutes, while the .dll is actually compiled.
This worked fine on our Visual Studio 2017 Build Server, (took a few seconds to compile I believe) but seems problematic with 2019.
Here's the code. Am I missing an MSBuild parameter or two?
$msbuild = """C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"""
# Rebuild the Test source .dll...
Write-Host "********** Running UI Tests **********"
# Restore Selenium packages...
Write-Host "********** Restoring Selenium Packages **********"
&"C:\Nuget.exe\Nuget.exe" restore $source\Development\12.0\Web\MyAppWeb\MyCo.SeleniumUITest\MyCo.SeleniumUITest.sln -DisableParallelProcessing
Write-Host "********** Selenium Packages Restored **********"
# Changes for new MSBuild....
$projfile = "$source\Development\12.0\Web\MyAppWeb\MyCo.SeleniumUITest\MyCo.SeleniumUITest.sln"
try
{
start-process $msbuild -ArgumentList #($projfile,'/t:Rebuild','/p:configuration=Release') -Wait
Write-Host "********** Selenium .dll compiled successfully! **********"
}
catch
{
Write-Host $_.Exception.Message
exit 1
}
Any Help Appreciated! If this should go in the PowerShell forum, let me know. I thought TFS/MSBuild would be the correct place as I'm hoping its just a parameter or call tweak.

MSBuild Running Slow Called from PowerShell Script (Visual Studio 2019)
State:
(It is difficult to give an accurate answer to this question of operating efficiency. There are many reasons for the problem, most of which are related to the environment, making it difficult for us to reproduce it. So we could not give the direct correct answer for this issue, we can only give you some troubleshootings. In order to avoid losing contact in the round-trip comments, I post those troubleshootings as answer instead of comments.)
First, use the script with Azure devops service instead of the TFS Build Server 2019, to check if this issue still occurred on the Azure devops service, if this issue also occurred on the Azure devops service, that mean this issue should not related to the TFS, more related to the MSBuild/environment/powershell scripts.
Second, use the build in task nuget restore and msbuild task instead of the powershell scripts, to check if you have this issue, if also have this issue, this issue should not related to the scripts. If not, this issue should related to the scripts. We need to check if this scripts need to update since we use the different TFS server.
Third, Check the powershell version in the Visual Studio 2017 Build Server and Visual Studio 2019 Build Server, make sure they use the same version.
If you still could not find the reason, you could enable the debug log and share the log about the hangs to us, so that we could get some more info.
Hope this helps.

I moved the MSBuild scripted tasks out to Build Definition tasks to remove the slowness. I did not determine the cause of the hang when MSBuild was called via the PowerShell script.
The later issue of trying to publish via a .proj file was solved when I noticed I was using a Visual Build task instead of the more appropriate MSBuild task.
One thing to note when using the MSBuild step. If pointing to a .proj file and compiling for Any CPU, set it in the Task as AnyCPU with no space in between.

Related

Restore x64 NuGet packages via PowerShell

I've got .NET 7.2 WEB API project, which was build with x64 Visual Studio 2022 v17.2 - v17.4. Now I try to set up CI/CD pipeline, for what I use .yml with following code:
- 'C:\nuget.exe restore server.csproj'
- '& "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild" server.csproj'
Constantly getting error:
error NETSDK1064: Package Microsoft.EntityFrameworkCore.Analyzers, version 7.0.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
What I've tried is:
I enabled Win32 long paths as it suggested here
I've created new WeatherForecast project and new repo with name tst, so path certainly cannot be shorter
Nothing gives any success
As far as I understand, the problem is that I use x32 NuGet CLI with x64 VS 2022 builder. Bit depth does not match. As far as my project uses .NET 7, I cannot use VS 2019. Also I cannot find x64 NuGet CLI - official site provides only x32 versions
I need some way to restore packages and then build the project from YML file. What surprised me is that I can sequentially run all commands from .yml in cmd.exe and as a result I will get build with no errors. I tried to $ whoami prior to any of .yml command and it gives me that it's SYSTEM user, which by the way got full access to IIS's wwwroot folder, but the error triggers prior deployment step, so I have no clue how it could be related
I'm stuck, got no idea what to do, but guess that solution is quite simple, I'm to blurry now. SOers please help me
Solution
Great thanks to #mu88!
In accordance to his suggestions yml took that form:
- 'dotnet restore service.csproj -v n'
- 'dotnet service.csproj'
And everything works as it supposed to
After some investigation (see the comment section) we found out that using dotnet build instead of msbuild solves the problem.

"error: MSB4040 There is no target in the project" when using MSbuild+Delphi10.2

I'm automating the build of a Delphi 10.2 project
I'm using msbuild with .net 4.0.30319
I'm running rsvars.bat to set the environment variables and then call MSBuild
start-process "C:\Program Files (x86)\Embarcadero\Studio\19.0\bin\rsvars.bat"
MSBuild Modulos/COM/PCOM.dproj
Probably the solution will be something simple and basic that I didn't pay attention to and I'll be mulling over it for days after it's solved
I found some articles related to the topic, but none were able to solve my problem.
https://stackoverflow.com/questions/1342859/error-msb4040-there-is-no-target-in-the-project-when-using-msbuilddelphi2009
https://stackoverflow.com/questions/33564315/how-to-build-a-delphi-project-in-teamcity
I manage to simulate the error through the windows powershell
error in the windows powershell
If i run it through the command prompt I get success, but running through Jenkins does not object success.

Build project using devenv.exe in TFS 15RC1 Build Server

I have a trouble with understanding how to use devenv.exe from TFS Build Server.
There is no default step to use devenv, so I tried to use PowerShell sсript to execute devenv.exe with parameters. There are no errors in build process but I see that build result files are not updated.
If I execute the script manually on a agent-machine, the build passes successfully. That is my script:
$process = [System.Diagnostics.Process]::Start( "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe", "/Rebuild ""MyConfig"" ""C:\agent\agent\_work\1\s\MyProject.sln"" /Project ""C:\agent\agent\_work\1\s\MyProject\MyProject.dwproj""")
$process.WaitForExit()
As you see now I do not use variables for source paths, but I will use it if script will work.
I also have to say that I could not find any logs with errors. Maybe I do not know where to find them?
So,
What am I doing wrong in powershell script?
What is the best practice to build project using devenv.exe in TFS Build Server?
PS We are using TFS 15 RC1 (Version 15.103.25603.0).
For now, there is no this build-in feature to support directly using devenv.exe in vNext build task. But seems will coming in the near future:
That is not something we are working on right now, but it is something
that we would take a pull request for.
chrisrpatterson commented on Jan 8
We want an input on the existing Visual Studio Build task that says
use devenv (defaults to false). If true, it takes the variant path
running code similar to above.
bryanmacfarlane commented on Jan 22
Source from GitHUB:
"Visual Studio Build" build step that actually invokes devenv.com instead of msbuild?
visual studio command-line build vnext step (devenv.com)
You can try to use a pull request provide by jmacnett which creating a customize build task.
I found that it doesn't work only when the agent is running as a service. When I started the agent in the interactive mode, my tasks started to work correctly. Why? - I don't know.
$argumentList = ("`"$solnPath`" /$solnCmdSwitch $solnConfigName")
if project then add folowing
$argumentList += (" /project `"$projPath`" /projectconfig $projConfigName")
See the extra back-quotes

Get Build Version in automated build deployment using TFS

I am deploying web application to azure using TFS CI automated build deployment.
In our config maintain build version like 2014.05.19.1 which is $(Date).$(rev) format.
All I want to update config each time build is deployed.For that I am passing value to 'BuildVersion' parameter in template to powershell script which actually performs publishing to azure.
I tried using $(Date:yyyyMMdd)$(Rev:.r) but it is considered string as it is.
I want to get current build version just like IBuildDetail.BuildNumber
within template.
My question is how to get the build version?
If you are using Invoke Process, instead of passing value for BuildVersion parameter you can directly use 'BuildDetail.BuildNumber' in parameters for process like
String.Format("-BuildNumber ""{0}""",BuildDetail.BuildNumber)
This would give the required build number.
If your PowerShell script is being executed from your TFS build, it should have access to the environment variables specific to the TFS context of the build. If that is the case, you actually don't need to pass the $(BuildVersion) parameter to the script, as it already is accessible to the PS script in the $env:TF_BUILD_BUILDNUMBER environment variable. Try testing something like $env:TF_BUILD_BUILDNUMBER | Out-File "D:\Dev\BuildNumber.txt" in your script. You should hopefully see the file containing your build number after running your build.
(I am assuming you are using a relatively new build process template...one that contains the "Post-Build script path" parameter, such as TfvcTemplate.12.xaml)
Hope this is helpful.
I would recommend that you use the right tool for the right job. The build system, is really only for building (compile & test). We have been using it for other things for years coz we did not have another integrated solution. However Microsoft recently bought InRelease and rebranded as Release Management for Visual Studio 2013. I have successfully integrated this with TFS 2012 as well.

TFS Web Deploy doesn't execute via Build but executes locally?

I have a solution that I am trying to get TFS 2010 to deploy after it builds.
When I run the following msbuild command locally, it deploys fine:
msbuild C:\Path\to\Solution.sln /p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=True /p:MSDeployPublishMethod=WMSVC /p:MSDeployServiceUrl=https://[Server]:8172/MsDeploy.axd /p:DeployIisAppPath="TestSite" /p:UserName=Domain\Username /p:Password=NotTheRealPassword /P:AllowUntrustedCertificate=True
However, when I stick those same options into the TFS 2010 build MS Build arguments:
...it doesn't appear to execute anything.
The build finishes correctly:
But I see nothing in the entire log file related to deployment, etc. It's as if the parameters were never even passed in to MSBuild from TFS.
The MSBuild Command Being Called by TFS
The log has it as (scrubbed sensitive data): C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /noconsolelogger "C:\Builds\1\[Scrubbed]\Daily6am\Sources\[Scrubbed].sln" /m:1 /fl /flp:"logfile=C:\Builds\1\[Scrubbed]\[Scrubbed]\Sources\[Scrubbed].log;encoding=Unicode;verbosity=normal" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=True /p:MSDeployPublishMethod=WMSVC /p:MSDeployServiceUrl=https://[Scrubbed]:8172/MsDeploy.axd /p:DeployIisAppPath="TestSite" /p:UserName=[Scrubbed]\farmservice /p:Password=[Scrubbed] /p:AllowUntrusted=True /P:AllowUntrustedCertificate=True /p:OutDir="C:\Builds\1\[Scrubbed]\[Scrubbed]\Binaries\\" /p:Configuration="Debug" /p:Platform="Any CPU" /p:VCBuildOverride="C:\Builds\1\[Scrubbed]\[Scrubbed]\Sources\[Scrubbed].sln.Any CPU.Debug.vsprops" /dl:WorkflowCentralLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/23;InformationNodeId=4504;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://[Scrubbed]:8080/tfs/[Scrubbed]_Collection;"*WorkflowForwardingLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;"
Questions
How can I get TFS to tell MSBuild to build the deployment?
How can I verify whether the parameters were even passed in?
How can I correctly read the logs to know if this has taken place or not?
Assistance on any of these would be much appreciated.
I was able to find the answer on a SO question from a bit ago :)
According to the answer at this SO Question, #marvc1 (credit where it's due) suggested copying the following files:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications
I had copied WebApplications, but not Web. Copying web resolved the issue.