I have defined the postbuildevent in project which is working fine locally but when called from Teamcity it is not calling the following event:-
<PropertyGroup>
<PostBuildEvent>xcopy /Y /E "$(TargetDir)\Shared\Scripts" "$(ProjectDir)\Shared\Scripts"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
I tried passing via command line parameters in msbuild configuration of teamcity but that is also not working
/M /P:Configuration=%system.Configuration% /P:PostBuildEvent="xcopy /Y /E "$(TargetDir1)\Shared\Scripts" "$(ProjectDir1)\Shared\Scripts""
Please guide.
Related
So, I created a publish profile for my web app. I did this with the GUI in VS 2017 Enterprise. I then found an example of how to change the pubxml to make it zip all the output files. Eventually I ended up with this:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>True</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>bin\Release\Publish</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<Configuration>Release</Configuration>
</PropertyGroup>
<Target Name="ZipPublishOutput" AfterTargets="GatherAllFilesToPublish">
<Exec Command='powershell -nologo -noprofile -command "compress-archive -force -path $(WPPAllFilesInSingleFolder)\* -destinationpath $(publishUrl).zip"' />
</Target>
</Project>
This works perfectly fine if I do a publish through Visual Studio. However, I've been trying everything I can think of to get this to work in MSBuild, with no luck.
Here is an example of what I think should work:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" WebApp.csproj /nologo /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=ReleasePublish
And for reference, here is the version of MSBuild:
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
I know MSBuild is finding the profile pubxml because I can make a change to the settings, such as publishUrl, and those changes are applied the next time I run MSBuild. What doesn't seem to work is the ZipPublishOutput target. And even running MSBuild with diagnostic verbosity shows that GatherAllFilesToPublish never runs, which would mean my target wouldn't run.
I've found many different suggestions and nothing seems to help. A lot of the solutions I found seemed to be with MSBuild not finding the pubxml, but that's not the case here.
So, is GatherAllFilesToPublish something that is Visual Studio specific, and therefore MSBuild doesn't know about it? That seems like how it's acting.
Just got the same problem using msbuild with Jenkins.
To execute the target GatherAllFilesToPublish with msbuild I had to add the target /t:GatherAllFilesToPublish in the msbuild command line.
You should have something like this :
/p:DeployOnBuild=true /p:PublishProfile=fullPathToMyPubXML.pubxml
/t:GatherAllFilesToPublish
I've just implemented a new build script file to share code signing details among projects and allowing us to easily switch depending on if our main certificate is available or not. This is in our main application project as well as two WiX projects (msi and exe).
It seems like WiX remembers settings from the last build - for example, if I build with cert.sign in the correct place, then remove it and build again, it recalls the settings loaded from cert.sign during the first build rather than using test.sign as expected. This is not an issue in regular .csproj files.
The .sign file I've set up (one per certificate):
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Certificate>test.pfx</Certificate>
<FilePath>$(SolutionDir)</FilePath>
<Pwd>cert_pwd</Pwd>
<TimeStamp>/tr http://timestamp.server.com</TimeStamp>
<AppName>My App</AppName>
<Url>www.example.com</Url>
</PropertyGroup>
</Project>
The main .csproj file (this works):
...
<Import Project="$(SolutionDir)..\..\.cert\cert.sign" Condition="Exists('$(SolutionDir)..\..\.cert\cert.sign')"/>
<Import Project="$(SolutionDir)\test.sign" Condition="!Exists('$(SolutionDir)..\..\.cert\cert.sign')"/>
<PropertyGroup>
<PostBuildEvent>signtool sign /f $(FilePath)$(Certificate) /p $(Pwd) $(TimeStamp) /d $(AppName) /du $(Url) $(TargetPath)</PostBuildEvent>
</PropertyGroup>
...
One of the .wixproj files (this doesn't work):
...
<Import Project="$(SolutionDir)..\..\.cert\cert.sign" Condition="Exists('$(SolutionDir)..\..\.cert\cert.sign')"/>
<Import Project="$(SolutionDir)\test.sign" Condition="!Exists('$(SolutionDir)..\..\.cert\cert.sign')"/>
<Target Name="SignMsi">
<Exec Command="signtool sign /f $(FilePath)$(Certificate) /p $(Pwd) $(TimeStamp) /d $(AppName) /du $(Url) #(SignMsi)" />
</Target>
...
Any ideas on how to fix this? Could it be an issue in the SignMsi and SignExe targets? I'm on Visual Studio 2015 u2, WiX v3.10.2.2516
I have a targets file which uses the MSBuild task to compile bunch of .csproj files. This works as expected.
Is it possible to take the properties from the commandline?
<Target Name="MyBuild">
<MSBuild Projects="#(Projects)" Properties="FROM COMMAND LINE"/>
</Target>
msbuild mybuild.proj /p:myProperty=true
You can do something like this:
<Target Name="MyBuild">
<MSBuild Projects="#(Projects)" Properties="$(MyProperties)"/>
</Target>
and call MSBuild this way:
msbuild mybuild.proj /p:MyProperties="MyProperty=true;MyOtherProperty=false"
Environment variables can be used to set MSBuild properties. We use batch files to set env variables based on command line parameters, which then invokes MSBuild after setting env variables based on the command line parameters.
I've got a task in my MSBuild file like so:
<Exec command="net use $(DeploymentServerName) /user:username passwd" ContinueOnError="false" />
But in the console output it will dump the command:
...
net use $(DeploymentServerName) /user:username passwd
...
But I'd like to hide the credentials, if possible. I don't care about where the output of the command goes, I just care that the command itself is not echo'd to the console. Any ideas?
Starting with .NET 4.0 Exec MSBuild task got property EchoOFF which allows to achieve exactly that - suppress echoing of the command itself (not the command output). Full documentation is here. Just add EchoOff="true" to the list of Exec properties.
There are a couple of possible approaches, here is one
<Target Name="DoHideCommand">
<Exec Command="MSBuild $(MsBuildThisFile) /t:SpecialCommand /nologo /noconsolelogger"/>
</Target>
<PropertyGroup>
<MyCommand>dir c:</MyCommand>
</PropertyGroup>
<Target Name="SpecialCommand">
<Exec Command="dir"/>
</Target>
This invokes a seperate msbuild process to invoke the actual target, and hides all output resulting in
...
DoHideCommand:
MSBuild test.targets /t:SpecialCommand /nologo /noconsolelogger
...
And here is another one
<Target Name="SpecialCommandViaFile">
<PropertyGroup>
<TmpFile>tmp.bat</TmpFile>
</PropertyGroup>
<WriteLinesToFile File="$(TmpFile)" Lines="$(MyCommand)"/>
<Exec Command="$(TmpFile) > NUL 2>&1" WorkingDirectory="$(MsBuildThisFileDirectory)"/>
<Delete Files="$(TmpFile)"/>
</Target>
This creates a batch file to run the actual command, then redirects all output to NUL so only this is shown:
...
SpecialCommandViaFile:
tmp.bat > NUL 2>&1
Deleting file "tmp.bat".
...
Note though that the one executing your msbuild file can always simply open your file to look at the credentials, even if they are hidden from the output when running it.
I'm trying to do some MSBuild automation for deploy and backup. I tried several different remote execution platforms (Powershell/WMI, PsExec and Cygwin) and had some troubles with all of them.
With Powershell and PsExec, I think the problem is some security baselines used on the machines. I don't have full control of the machines and domain.
The most stable scenario I found is with cygwin/openssh. But when I'm running plink inside MSBuild and trying to invoke MSBuild remotely, msbuild hangs without telling me the error. If I run directly plink from prompt, everything works fine.
The MSBuild script follows:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Plink>"c:\Program Files (x86)\PuTTY\plink.exe"</Plink>
<UserName></UserName>
<Password></Password>
<HostName>localhost</HostName>
<RemoteCommand2>/cygdrive/c/SandBox/remotemsbuild/echoalotoffiles.bat</RemoteCommand2>
</PropertyGroup>
<Target Name="Build">
<Exec Command="$(Plink) -l $(UserName) -pw $(Password) -batch $(HostName) $(RemoteCommand2)" />
</Target>
<Target Name="EchoALotOfFiles">
<ItemGroup>
<SandBoxFiles Include="$(MSBuildProjectDirectory)\..\**\*.*" />
</ItemGroup>
<Message Text="#(SandBoxFiles)" />
</Target>
</Project>
When I run the first target, Build, I have the issue (MSBuild hanging)
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.17929]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 02/11/2013 12:01:45.
Project "C:\SandBox\remotemsbuild\remotemsbuild.build" on node 1 (EchoALotOfF
iles target(s)).
EchoALotOfFiles:
If I run just plink from command line, everything works fine.
Any guesses?