TeamCity Build Failure - msbuild

I have tried many things today to get my build to work in Teamcity but to no avail.
Here is my setup.
I have 2 build configurations in TeamCity
Build Solution
Build Deployment Package Debug
Build Solution is triggered by an SVN checkin and builds the solution file. This configuration works fine.
Build Deployment Package Debug has Build Solution as its dependency and has two (MSBuild) build steps. The solution contains two websites: a front end one and an admin one. One build step builds the front end site and the other the admin site. The end result is that it puts the combined results into a zip file for deployment to the deployment server (I've not got to this bit yet).
The problem that I have is that the Build Deployment Package Debug configuration fails trying to build the first site. This is the error:
[18:40:25]Step 1/2: Web (MSBuild) (29s)
[18:40:28][Step 1/2] x.Web\x.Web.csproj.teamcity: Build target: Build (27s)
[18:40:50][x.Web\x.Web.csproj.teamcity] MvcBuildViews (4s)
[18:40:50][MvcBuildViews] AspNetCompiler (4s)
[18:40:55][AspNetCompiler] C:\BuildAgent\work\252ec59002ecc2d\x.Web\obj\debug\csautoparameterize\original\web.config(39, 0): error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
[18:40:55][x.Web\x.Web.csproj.teamcity] Project x.Web\x.Web.csproj.teamcity failed.
[18:40:55][Step 1/2] Step Web (MSBuild) failed
Here are Build Paramters -> System Properties
Name Value
system._PackageTempDir c:\deploypackage
system.Configuration Debug
system.CreatePackageOnPublish True
system.DeployIisAppPath Debug
system.DeployOnBuild True
system.PackageLocation c:\buildshares\Debug\Debug.zip

Here's what I did to solve this
I already had this in my project file
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
But I needed to add this also
<Target Name="AfterBuild">
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
Doing this fixed the issue.
I hope this helps someone else who is working on TeamCity in the future.

Related

How to kill VBCSCompiler.exe on Ubuntu agent?

I created an Azure Devops Build pipeline and i am trying to build my ASP.NET MVC and Angular hybrid site project on bitbucket (git).
The project first gets checked out, and nuget restores the necessary packages, and then the .NET builds. I used windows 2019 as azure pipeline agent for the build to succeed. however, Its taking about 7 minutes to complete, whilst running the tasks (besides .Net) on a ubuntu agent is much faster! takes around 2 mins instead!
Therefore, I'd like to use ubuntu, but im running into an issue with the MSBuild task...
"/home/vsts/work/1/s/Bobby.ProjectA/Bobby.ProjectA.csproj" (default target) (1) ->
(KillVBCSCompilerAndRetryCopy target) ->
/home/vsts/work/1/s/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8/build/net45/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props(23,5):
error MSB4044: The "KillProcess" task was not given a value for the required parameter "ImagePath". [/home/vsts/work/1/s/Bobby.ProjectA/Bobby.ProjectA.csproj]
According to this post, VBCSCompiler.exe continues running from the Compiler Nuget package (nuget restore task?) so it locks the src folders and prevented future builds from running, e.g. causing error like this:
/home/vsts/work/1/s/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8/build/net45/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props(17,5):
warning MSB3021: Unable to copy file "/home/vsts/work/1/s/packages/Microsoft.Net.Compilers.2.4.0/build/../tools/csc.exe" to "/bin/roslyn/csc.exe". Access to the path '/bin/roslyn' is denied. [/home/vsts/work/1/s/Bobby.ProjectA/Bobby.ProjectA.csproj]
So the solution would be to kill the VBCSCompiler.exe but since i cant actually access the hosted machine during the build, im not sure how to do that.
screenshot of my pipeline so far:
Am i facing a dead-end path here with this approach? The build runs fine on windows 2019 but it just takes too long, so thats why if i can make it run on ubuntu successfully that would be great!
You can have a try with below workarounds:
1,Set MSBUILD arguements /p:UseSharedCompilation=false.
You can add above arguement to the msbuild arguements field of the msbuild task. See here.
2,Upgrade Microsoft.CodeDom.Providers.DotNetCompilerPlatform nupkg to the latest and remove Microsoft.Net.Compilers nupkg from your project. See here for more information.
3, Try Specifing the TTL of Roslyn compiler server.
You can define a pipeline variable VBCSCOMPILER_TTL on the Variable tab to specify a shorter idle time for VBCSCompiler.exe
Or you can add <providerOption name="CompilerServerTimeToLive" value="[num of seconds]" /> under system.codedom/compilers/compiler in the config file. See here for more information.
4, Use CheckIfShouldKillVBCSCompiler target:
You can try add below to your csproj file:
<Target Name="CheckIfShouldKillVBCSCompiler">
<PropertyGroup>
<ShouldKillVBCSCompiler>true</ShouldKillVBCSCompiler>
</PropertyGroup>
</Target>
See here.
The build on Ubuntu 20 finally worked! I don't know why removing these lines resolved the VBCSCompiler issue, but by doing so, the msbuild completed successfully on Ubunutu 20 agent!!
Remove the following lines from the .csproj file:
<Import Project="..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props')" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
To give some context to the answer, this post here indicated that converting from MSBuild-Integrated Package Restore to Automatic Package Restore (nuget restore task) implied that the Microsoft.Net.Compilers <Import> and <Error Condition> snippets are no longer relevant/needed in the .csproj file.

How do I disable Teamcity deploying artifacts for personal builds?

I am using Teamcity 9.0.2 and IntelliJ 14.1.5. I have a Teamcity build with a maven step configured with "Deploy Maven artifacts" enabled.
When I run a personal build, the artifacts get deployed to artifactory.
How do I disable deploying artifacts for personal builds by default for each of my builds?
Currently it's not possible to execute build steps based on condition. Vote for the related request: https://youtrack.jetbrains.com/issue/TW-17939.
As of now you can:
Create a separate build configuration without Deploy build step (recommended). You can use templates to simplify the setup. In this case it will be easier to interpret the results and the statistics of the builds will be informative.
If build is personal %system.build.is.personal% parameter is set to true. So you can check a condition in the build step and skip it if needed.
This is the workaround i found to this issue. I created two additional build steps, The first labeled "Check for Personal Build" is a Nant step that validation against the BUILD_IS_PERSONAL environmental variable, and if set, updates a teamcity env.PublishPath variable.
<project name="UpdateForPersonal" default="default">
<target name="default">
<if test="${environment::variable-exists('BUILD_IS_PERSONAL')}">
<echo message="##teamcity[setParameter name='env.PublishPath' value='fake']" />
</if>
</target>
</project>
The second step is a simple CMD the writes as dummy "Publish" message to the logs, but the "Custom published artifacts" values is from the "Deploy Artifacts To Artifactory" section padded by %env.PublishPath%.
If the build is personal, the publish to artifactory will not find any files and log warnings into the logs, but the build passes and no artifacts are published.
The value of %env.PublishPath% is set to "" by default in the configuration build.

MSBuild - how to force "AfterBuild" target when I do deployment?

I have the following setup: ASP.Net MVC .Net 4.0 solution with 5 projects in it, and several solution configurations (Site1-Stage, Site1-Live, Site2-Stage, etc). The reason for this is simple - we deploy same codebase to multiple servers with different config settings.
To manage these configurations, I use the approach described by Troy Hunt in his You're deploying it wrong! TeamCity, Subversion & Web Deploy part 1: Config transforms article. In 2 words - I do NOT have web.config in my SVN repo, instead I have Web.Base.Config, Web.Site1-Stage.Config, etc and XmlTransformation task in project AfterBuild target. During the build, the required web.config is generated based on selected configuration:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
<TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" StackTrace="true" />
</Target>
Here comes the problem: when I'm execute MSBuild like this:
msbuild MySolution.sln /P:configuration=Site1-Stage /t:rebuild
all goes well, web.config is properly generated for the Site1-Stage configuration. However, if I run this command:
msbuild MySolution.sln /P:configuration=Site1-Stage /t:rebuild /P:DeployOnBuild=True
I get the following error:
"MySolution.sln" (rebuild target) (1) -> "MySolution\MyWebProj.csproj"
(Rebuild target) (3) -> (PreTransformWebConfig target) -> C:\Program
Files
(x86)\MSBuild\Microsoft\VisualStudio\v10.5\Web\Microsoft.Web.Publishing.targets(1399,5):
error : Copying file Web.config to
obj\Site1-Stage\TransformWebConfig\original\Web.config failed. Could
not find file 'Web.config'. [MySolution\MyWebProj.csproj]
I tried to explicitly add "AfterBuild" target into MSBuild command line:
msbuild MySolution.sln /P:configuration=Site1-Stage /t:rebuild,AfterBuild /P:DeployOnBuild=True
but it resulted in the same error.
Why do I need this: it's a very isolated example, and in reality I'm trying to setup automated publishing from TeamCity CI server. I think if I add new build step with "Visual Studio (sln)" runner BEFORE my current publishing step, that would work, it will first rebuild the project (and generate web.config) - and then publish. However, i have lots of publishing steps (around 20 now) and I would like to avoid that. My understanding is that "Publish" process does the build as part of it, so I would like to "reuse" that.
Question is: how should I modify my MSBuild command line to force config transformation to happen?
Thank you.
Maybe use "BeforeBuild"?
BTW do you have web.config included in csproj? I believe most publish activities relies on items in project rather than in folder. You can include web.config in project, while still have excluded it from source control.

Why Unpublishable?

We have a solution that contains 17 projects.
Solution has several configurations such as Debug, Release, Test, Publish and etc.
Also team project has several build definitions, each one is specialized for a configuration.
We use Release configuration build for nightly builds and Publish configuration build for publish and deployment.
So these build definitions, build same source code. But there is a problem...
Our nightly build creates obj\Release directories for each project but publish build doesn't.
Because of this publish build doesn't create server publish package.
When I looked to the build logs I saw the differences like below.
Nightly build - Release configuration (for each project)
PrepareForBuild:
Creating directory "obj\Release\".
Publish build - Publish configuration (for each project)
_DeploymentUnpublishable:
Skipping unpublishable project.
But I couldn't understand why?
Which flag controls this?
We are using TFS 2010, so Team Build 2010.
Try adding the following deployment settings to the project file inside the property group for the build configuration you want to publish:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
<FilesToIncludeForPublish>OnlyFilesToRunTheApp</FilesToIncludeForPublish>
<DeployOnBuild>true</DeployOnBuild>
<DeployTarget>Package</DeployTarget>
<PackageAsSingleFile>true</PackageAsSingleFile>
</PropertyGroup>
I was getting a similar error on a web project's CI build. Adding the deployment settings to the web.csproj file corrected it.

Team Foundation Server 2010 - build configuration not set for project

(I´ve updated the title, to reflect my new findings)
I've just ported a bunch of projects from TFS2008 to TFS2010 and have run into a (actually several :)) problem with a specific project. When compiling with build configuration 'Debug', everything works as expected. However when compiling with build configuration 'Release' I get a linker error, due to al.exe cannot find the specified file in 'obj\debug'.
Error:
Task "AL" (TaskId:781)
...
ALINK : error AL1047: Error importing file 'c:\Builds\23\...\obj\Debug\someproject.exe' -- The system cannot find the file specified. [C:\Builds\23\...\Release\Sources\...\someproject.csproj]
The command exited with code 1. (TaskId:781)
Done executing task "AL" -- FAILED. (TaskId:781)
I've enabled the team build info diagnostic logging and found the following variable:
IntermediateOutputPath = obj\Debug\
My question is why would the linker look in the Debug folder, when I'm building under the release configuration. I've inspected the solution and project configuration and there are no 'Debug' configurations under the release solution configuration. Any ideas why this is happening and how to resolve it?
Thanks in advance.
!! Bonus info
I have the following statement in the project file that is failing, assuring if the build configuration is unspecified, it will be set to Debug.
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
I've tried to change it to Release as default and now my debug team build fails, pointing at obj\release instead. So it seems that the build configuration is unspecified, when the project is compiled. How can this be?
Found the problem. I have to set the build configuration explicitly for my publish target defined in the someproject.csproj project file. I've inserted the line 'Configuration=Release'
<MSBuild ToolsVersion="3.5" Projects="$(SolutionRoot)\...someproject.csproj"
Properties="RunCodeAnalysis=false;
Configuration=Release;
ClrVersion=2.0.50727.0;
ApplicationVersion=$(VersionNumber);
UpdateUrl=$(DevtestUpdateUrl);
InstallUrl=$(DevtestInstallUrl);
IsWebBootstrapper=true;
PublishDir=$(DropLocation)\$(BuildNumber)\Publish\Update\;
SolutionDir=$(SolutionRoot)\Kl******\;
DeploymentConfiguration=devtest;
SignManifests=true;
ManifestCertificateThumbprint=23...23;"
Targets="PublishOnly" />