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

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.

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.

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

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.

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

TFS - Run Powershell script against package before Deployment

I currently have a CI Setup in TFS 2013 which does the following
Pulls code down from Git on every commit to a branch
Builds the Solution
Runs N-Unit Tests Against the solution
Runs Jasmine Front-end Tests against the javascript
Deploys on success via WebDeploy to chosen server.
I have now managed to install Grunt and NodeJS on the server to do some manipulation of the Javascript between steps 5-6. Does anyone have any advice on how this might be done?
I've tried post-tests scripts to minify the javascript successfully on both the src and bin/_PublishedWebsites directory but this does not seem to persist over to the deployment server. And infact, the _PublishedWebsites route puts the build folder in an undeletable state due to maxmimum character limits on Windows files (argh).
You should switch over to using Release Management for Visual Studio 2013 (works with 2012 as well). This allows you to parameterize your release and push the same output through multiple environments. Very configurable and even makes sure that the tools you need end up on the server that you are deploying to. Supports Puppet, Chef, DSC, and create your own.
http://nakedalm.com/installing-release-management-server-tfs-2013/
And for an overview: http://nakedalm.com/building-release-pipeline-release-management-visual-studio-2013/
I managed to get this working with the addition of two extra steps to the pubxml file used for the deployment.
First, i added a dependency powershell script which ran NPM install and grunt tasks.
<PipelineDependsOn>
CustomBeforePublish;
$(PipelineDependsOn);
</PipelineDependsOn>
<Target Name="CustomBeforePublish">
<Exec Command="powershell.exe -ExecutionPolicy Unrestricted -file Pre_Deploy_Javascript_Build.ps1 $(ProjectDir)"/>
</Target>
Following this. I had now created additional files which did not exist in the project. I had to now ensure that these were published. To do this, i added another step.
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CopyMinJSFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn >
<Target Name="CopyMinJSFiles">
<ItemGroup>
<_MinJSFiles Include="$(ProjectDir)\App\*.js" />
<FilesForPackagingFromProject Include="%(_MinJSFiles.Identity)">
<DestinationRelativePath>App\%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>

Invalid file names when trying to deploy SSDT project with TeamCity 8

I am trying to deploy Visual Studio 2012 SSDT project to Sql Server using TeamCity 8 and MSBuild Publish task but the deployment fails.
When I look at TeamCity logs and use /v:diag switch in my build configuration I see that for unknown reason MSBuild searches for MyProject.sqlproj.publish.sql and for MyProject.sqlproj.dacpac files.
The exact error:
[SqlPublishTask] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(1233, 5): File "C:\Program Files\TeamCity\buildAgent\work\abf8bc05a2cfe7f\*MyProject*\bin\Debug\*MyProject*.sqlproj.dacpac" does not exist.
The correct .sql and .dacpac files get generated (without the .sqlproj in the middel) in buildAgent/work/identificator/*MySolution*/MyProject/bin/Debug folder.
My TeamCity build step is configured as follows:
Runner type: MSbuild
Build file path: MyProject/*MyProject*.sqlproj
MSBuild version: 4.5
MsBuild ToolsVersion: 4.0
Run platform: 4.0
Targets: Publish
Command line parameters: /p:SqlPublishProfilePath="Debug.publish.xml" /p:Configuration=Debug
If I execute this from commandline I get no errors.
Any ideas on how can I configure TeamCity to search for correct files or configure my project to generate the files that TeamCity is searching for.
Or is my plan to use MSBuild's Publish task futile and I should utilise sqlpackage.exe instead?
UPDATE
After spending almost three days trying to figure this out I gave up and used sqlpackage.exe which works like a charm.
But I would still be interested in an answer though, passing paths to executables in build servers seems a bit crude way to accomplish things.
I had a similar issue and came to the conclusion that the way TeamCity produces "pseudo-project" files with *.teamcity suffixes is confusing something in the MSBuild/SSDT target chain.
I simply replaced the MSBuild runner build step with a pure Command Line step and the problem went away.
We lose the user friendliness of the TeamCity MSBuild runner configuration, but if it works, it's a compromise I'm willing to make.
Note - we are running TeamCity 7 - I am not sure if this has been addressed in later versions.
I found out you can set a System Property named "system.SqlTargetName" on the build configuration to override the default value.
Setting this to your project name without the ".sqlproj" makes the error go away.