Nant script - How to check if it runs on a server or on a dev machine? - nant

I have a Nant build script.
It may be executed on either dev machine or build server.
I want to skip a build step on a dev machine but still run it on a server.
How can I check if the script runs on a server or on a dev machine?

It's all about adding something special to the build server. I can think of two options from the top of my head:
Environment variable: just make sure build server has a specific environment variable and check its existence in your NAnt script
Special environment.include file: make sure build server has a special environment.include file in the root of the C drive, for example, and define build server specific NAnt properties there, like <property name="is.build.server" value="true" />.
You can include this kind of file like this:
<include buildfile="\Environment.include" if="${file::exists('\Environment.include')}"/>

Related

Any way to run commands/script after VS2015 Publish wizard has copied files to output?

I have a very simple Windows service project I want to deploy to a server using Visual Studio 2015. I can successfully deploy using the Publish wizard (right-click on project -> Publish and deploy to \\myserver\c$\somepath\), but I need to 1) stop the service before publishing (so that the executable can be replaced), and 2) restart the service after the files have been copied.
I know how to start/stop services from the command line, and this answer provides a way to do it directly in a build action. However, I can't seem to find a way to execute any action after VS has copied the files to the output directory on the server.
For example, I have tried adding the following to my .csproj file without luck:
<Target Name="Mytarget" AfterTargets="AfterPublish">
<Warning Text="After AfterPublish" />
</Target>
Mytarget executes before VS actually copies the files to the server, so evidently, I can't hook onto AfterPublish. I've also tried PipelinePreDeployCopyAllFilesToOneFolder, CopyAllFilesToSingleFolderForPackage, and MSDeployPublish without luck (these don't seem to execute at all).
My end goal is to allow more-or-less one-click updating of the service, without having to log on to remote desktop and run a script manually after each update.
Is there any way I can have VS automatically execute an action after publishing a Windows service project to a server?

msbuild not able to write to files

I'm trying to create a build process using cruise control 1.8.5.0 with TFS 2010 running on a windows server 2008 R2 machine. The problem I'm running into is when MS Build is trying to write to files that ere just copied into the projects area it gets access denied. When I look at the files they are set to read only, the account that ccnet is running as is an admin on the box and everything is reading and writing locally. We have a similar environment setup on Windows Server 2003 and everything works just fine. We've verified that the account that is running the process is correct, I've set the owner of the projects folder to the same account that is running the process, we've disabled UAC. At this point I'm at a loss. Any additional information needed let me know.
Thanks
Robert
//When I look at the files they are set to read only, //
You can run the attrib to remove the read-only flag on the files.
quick example:
<Exec Command=“attrib -R $(SolutionRoot)\MyCoolFile.txt“ />
There is also a custom task:
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Attrib" />
I've not used it, but that would be enough to hunt it down.
I'd guess it would look like this:
<ItemGroup>
<Files Include="$(SolutionRoot)\MySubFolder\**\*.*/>
</ItemGroup>
<Attrib Files="%(Files.Identity)" ReadOnly="true"/>

Applying web.config transformations locally

I have a transform for my web.config that currently works if I publish to Azure, but it's not working locally when I build/run. How can I go about "Publishing" locally so the Local transformations are applied to my web.config on my dev box?
Currently I right-click > publish to Azure, do I need to create a new publish profile for my local box? Is there any way to get the transforms to work on Build instead?
It depends on which dev server you are using. As #Citronas said on this answer:
It depends on how you debug. If you are using Cassini, afaik your
web.config contents will be read regardless of the selected solution
configuration (e.g. Debug or Release).
If you are debugging with your
local IIS, it depends on what you have set the path in the IIS to. If
you have set it to your source code directory, you need to write your
local settings into your web.config. If you publish your code into a
local directory and set the IIS path accordingly, you can use
web.config transforms. (You said, that your web.config transforms are
working)
You do not need to publish locally (even though you can do that, publish to local IIS then attach the debugger to the worker process of the application pool) since it is annoying. The easiest way is to simple have your debug settings in the web.config file and then apply transforms for your "publishable" environments.
In short: do not use transforms for debug, only for publishing. Use the regular web.config to debug.

TFS Build Website deployment package web.config transformation not working

So I am trying to use TFS Build for generating deployment packages for my 3 environments (ST, UAT, Prod).
This what I followed to successfully genrate the package locally.
http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/74bb16ab-5fe6-4c00-951b-666afd639864/
So my local machine will generate the package for the acyive configuration and everything is good. Here is my Build definition :
/p:DeployOnBuild=true;DeployTarget=Package
I run my solution file and the web deployment project in the Projects To Build.
It creates the respective folders with ST, UAT and PROD. In each of these there is a _PublishedWebsites folder. This folder have 2 folders.
1) MydeploymentProject - It contains the transformed web.config
2) MyDeploymentProject_Package - Contains the Package folder contents along with the zip file and setparameters files. Here the everything is not transformed. But if I check the TempBuildDir on the TFS server it does contain the transformed config.
When compared the logs local and on server, I found that the on my local After transformation files are updated and package is created whereas on TFS the AfterBuild target is called transformation done and it ends there.
this is my local log
Target "WPPCopyWebApplicaitonPipelineCircularDependencyError" skipped, due to false condition; ($(WPPCopyWebApplicaitonPipelineCircularDependencyError)) was evaluated as (False).
Target "ProcessItemToExcludeFromDeployment" in file "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" from project "C:\TAX-IT\Main\Source\TDDB\TDDB_deploy2\TDDB_deploy2.wdproj" (target "PipelineCollectFilesPhase" depends on it):
Done building target "ProcessItemToExcludeFromDeployment" in project "TDDB_deploy2.wdproj".
Target "GetProjectWebProperties" in file "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" from project "C:\TAX-IT\Main\Source\TDDB\TDDB_deploy2\TDDB_deploy2.wdproj" (target "PipelineCollectFilesPhase" depends on it):
Using "GetProjectProperties" task from assembly "C:\Program Files\MSBuild\Microsoft\WebDeployment\v10.0\....\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll".
Task "GetProjectProperties"
I am not sure what is wrong.
Also I installed VS2010, web deploy 2.0 and 3.0 and web deployment tools on my Build servers.
Anyone have faced this and resolved.
Please help.
Thanks
MadCoder,
From what I've gathered from your description, you have everything set up correctly. It seems like you are just missing the "Configuration" parameter. When you do run the Build Definition, it uses the configuration specified in your "Configurations to Build" argument. If you want to have multiple configurations built (like you are suggesting), you'll need to have multiple configurations defined. One question I have is: When you look at the logs of the TFS Build Process, do you see multiple configurations built, or do you only see one? If you only see one, then you don't have all of the configurations defined in order to transform the config file. According to your description, you'll need to see something like this in your build definition configuration:
If you don't want to deploy to a webserver, you can stop reading here, and don't have to continue on.
If you choose to use a TFS Build Definition to deploy to a web server, you'll need to have a target web server somewhere and you'll need to install and configure the Web Deploy v2/v3 on that server as well.
When you are using TFS Build Definitions to deploy, the transformation happens upon deployment, not during packaging (prior to deployment). It may package up a transformed config somewhere, but it won't actually transform the config bundled with the website. The only way I've been able to get the deployment to actually work with a transformed config is when I had a website specified in the MSBUILD args. Here is an example of my MSBUILD args:
/p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MSDeployPublishMethod=RemoteAgent /p:MsDeployServiceUrl=MyWebServer/MsDeployAgentService /p:DeployIisAppPath="MyWebsite as named in IIS" /p:UserName=MyDomain\MyWebDeployUser /p:Password=MyWebDeployPassword
If you don't want MSBUILD to do the actual deployment (I prefer not to because then your deployment process is tied to TFS), you can do the deployment after the build process and use the CTT Project, found on codeplex. This tool performs the exact same transformations as MSBUILD, but it also includes the ability to parameterize settings so you can define classes of environments (for example, 3 QA environments, 2 Staging Environments, etc.) and still use the respective transforms for that class of environment.

Copy file to the App Resources directory if debug configuration is selected

I need to copy a few files into the App's Resources directory during debug builds. I am thinking about using build rules but don't know how to determine if the build is a debug build. I do have a compiler option of "DEBUG" set.
You can use a Run Script build phase to do the copying. All build settings applied when building the target are available via environment variables in your script.
You can determine what configuration is being built via the CONFIGURATION environment variable; you can look at other environment variables like BUILT_PRODUCTS_DIR to determine where to put your resource. If you specify your Run Script build phase's output correctly, it will only be run when the output needs to be brought up to date, not every time you build.
More information on Run Script build phases is available here: Xcode Build System Guide: Build Phases: Run Script Build Phase
The same kind of thing can be done with script build rules, which is useful if you have multiple resources you want to apply this to: You can create a script build rule that matches your extension (e.g. *.myresource) and use the build settings and input files that are passed to your script via environment variables to do the actual copying. If you specify your build rule's output correctly, it will only be run when its input is newer than its output, not every time you build.
More information on script build rules is available here: Xcode Build System Guide: Build Phases: Build Rules