I'm trying to build a solution with custom configuration "Staging" using MSBuild command parameter /p:Configuration=Staging, but I always getting the current configuration from solution properties and the parameter is ignored.
When I set the first project to Release and pass /p:Configuration=Staging, I still getting Release instead of Staging.
I'm using VS2017.
I print the message using
<Target Name="temp" BeforeTargets="PrepareForBuild">
<Message Text="Custom message Current configuration: $(Configuration)" />
</Target>
And I got the message Custom message Current configuration: Release
When I change the Configuration to Debug from solution property pages and build using MSBuild /p:Configuration=Staging, I got Custom message Current configuration: Debug
How can I override solution configuration when using MSBuild?
Update:
Here is the solution configuration
Related
I need to build at the solution level using MSBuild since I have multiple configurations. I have a custom target in my web project that publishes the output. I can specify the web project as the target and it builds fine. But I need to publish the web application. Is there a way to build a project's custom target when building at the solution level?
I found this link, but I don't understand the solution. If someone could break that down a little, it would help a lot.
This is what my current PowerShell command-line looks like:
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" `
"..\..\Solution.sln" `
"/t:WebApplication:PublishToFileSystem" `
"/p:Configuration=$configuration;PublishDestination=$publishPath"
The :PublishToFileSystem causes it to fail, with this message:
error MSB4057: The target "PublishToFileSystem" does not exist in the project. [C:\Source\Solution.sln]
This is what my custom target in my .csproj file looks like:
<Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
<Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
<MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
<ItemGroup>
<PublishFiles Include="$(_PackageTempDir)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(PublishFiles)" DestinationFiles="#(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" />
</Target>
So, after some research, I found that creating a custom target is not the best way to publish a web application. Assuming you have just one web project in your solution, MS extended MSBuild to use publish profiles (the same ones used when you publish in Visual Studio). I was able to create a separate publish profile for each configuration (environment) and call the following command line:
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" `
"..\..\Solution.sln" `
"/p:DeployOnBuild=true" `
"/p:PublishProfile=$configuration"
I just had to make sure my publish profiles had the same name as my $configuration.
I have an MSBuild/C# project having a target trying to access `%build.counter% parameter supposed to be set by TeamCity.
<Target Name="TraceBuildParameters" BeforeTargets="BeforeBuild">
<Message Text="Build.Counter=$(build_counter)" />
</Target>
I can access it in TeamCity project build settings but none of this work in the script:
build.counter // msbuild error
build_counter // null
system_build_counter // null
teamcity_system_build_counter // null
teamcity_build_counter // null
Is it possible to access this parameter at all, is it exposed?
TeamCity will send any system parameters to your MSBuild script (not configuration parameters). If you explicitly want the %build.counter% value, the easiest approach would be to set a system parameter as follows:
system.BuildCounter = %build.counter%
Then you should be able to reference it as $(BuildCounter).
Alternatively, the build.number is already sent to MSBuild as $(build_number). Depending on whether or not you've customised the build number on the Configuration -> General Settings tab, this may save the need for the extra parameter.
I have a solution with two default projects inside (VisualBasic console applications):
Solution1\
Solution1.sln
ConsoleApplication1\ConsoleApplication1.vbproj
ConsoleApplication2\ConsoleApplication2.vbproj
I have added a custom target to ConsoleApplication1:
...
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Target Name="HelloWorld">
<Message Text="Hello Build!"></Message>
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
...
</Project>
I would like to set up a script to execute a normal build on both projects, then call my custom target.
According to: http://msdn.microsoft.com/en-us/library/ms171486.aspx, I should be able to call the specific target with the following command (ignoring the initial build of the projects for now):
msbuild C:\Path\To\Solution1\Solution1.sln /t:ConsoleApplication1:HelloWorld
Instead, I get the following error message:
error MSB4057: The target "ConsoleApplication1:HelloWorld" does not exist in the project. [E:\Path\To\Solution1\Solution1.sln]
I presume I have the syntax incorrect, what would the correct syntax be to accomplish this?
The following commands work as expected:
msbuild C:\Path\To\Solution1\Solution1.sln
msbuild C:\Path\To\Solution1\ConsoleApplication1\ConsoleApplication1.vbproj /t:HelloWorld
Have you considered just adding your custom target action to the AfterBuild target in the desired msbuild proj file? It's a different approach, but would eliminate the need for the explicit invocation of the custom target and still be project file specific.
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.
(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" />