Is there a basic, standard .build file for NAnt? - asp.net

Basically, I'm trying to integrate CruiseControl.NET with NAnt. I've got CC.NET set up, but I'm getting an exception when it tries to build with NAnt.
BUILD FAILED - Could not find a '*.build' file in 'C:\inetpub\MyProject\'
Okay, no big deal, I just have to create a build file. Not sure what that is, but I found one in the HelloWorld example that came with NAnt, it looks like this:
<project name="Hello World" default="run">
<property name="basename" value="HelloWorld"/>
<property name="debug" value="true"/>
<target name="clean">
<delete>
<fileset>
<include name="bin/${basename}-??.exe"/>
<include name="bin/${basename}-??.pdb"/>
</fileset>
</delete>
</target>
<target name="build">
<mkdir dir="bin" />
<csc target="exe" output="bin/${basename}-cs.exe" debug="${debug}">
<sources>
<include name="${basename}.cs"/>
</sources>
</csc>
<jsc target="exe" output="bin/${basename}-js.exe" debug="${debug}">
<sources>
<include name="${basename}.js"/>
</sources>
</jsc>
<vbc target="exe" output="bin/${basename}-vb.exe" debug="${debug}">
<sources>
<include name="${basename}.vb"/>
</sources>
</vbc>
</target>
<target name="run" depends="build">
<exec program="bin/${basename}-cs.exe" basedir="."/>
<exec program="bin/${basename}-js.exe" basedir="."/>
<exec program="bin/${basename}-vb.exe" basedir="."/>
</target>
</project>
There's a lot more content in this file than I was expecting. I tried searching around to find out what everything meant, what was required, etc. But I couldn't find anything.
Is there just a basic and standard file that I could use? All I want to do is simply build my entire application, nothing crazy.

Nant's tasks and attributes are described here: NAnt Help
Task Reference
Also,
A Brief Introduction to NAnt
NAnt Starter Series
This article has a template:
The Anatomy of a NAnt Build File
Plus, previous SO question:
Simple HelloWorld build script

Related

Alfresco custom action dialog not showing

I created a custom Alfresco action dialog using one of the sample SDK projects
as a base. I kept the sample projects "org.alfresco.sample" package for my java files
and it worked fine.
Then I tried to change the package name to "com.xxxxxx.xxxxx" and it stopped working.
I have checked all of the files in the project to make sure that I have replaced every instance of "org.alfresco.sample" with my new package name.
Can anyone suggest a possible reason for this?
Thanks
I found that when I build the project, it is not building the java files. Can anyone
suggest why it is not building the java files with the new package name?
Thanks
I got the java files build again. But the new actions are still not being used. The new actions use an evaluator but it does not seem to be running. (It would normally write to
the log.)
Here is part of the build.xml:
<project name="Custom Dialog Build File" default="package-amp" basedir=".">
<property name="project.dir" value="."/>
<property name="build.dir" value="${project.dir}/build"/>
<property name="config.dir" value="${project.dir}/config"/>
<property name="jsp.dir" value="${project.dir}/web/jsp"/>
<property name="web.dir" value="${project.dir}/web" />
<property name="package.file.jar" value="${build.dir}/lib/custom-dialog.jar"/>
<property name="package.file.zip" value="${build.dir}/lib/custom-dialog.zip"/>
<property name="amp.file" value="${build.dir}/dist/retailChannels.amp"/>
<path id="class.path">
<dirset dir="${build.dir}" />
<fileset dir="../../lib/server" includes="**/*.jar"/>
</path>
<target name="compile">
<mkdir dir="${build.dir}" />
<javac classpathref="class.path" srcdir="${project.dir}/source" destdir="${build.dir}" />
</target>
<target name="package-jar" depends="increment-build-number">
<delete file="${package.file.jar}" />
<jar destfile="${package.file.jar}">
<fileset dir="${build.dir}">
<exclude name="dist/**" />
<exclude name="lib/**" />
<exclude name="web/**" />
</fileset>
</jar>
</target>
<target name="mkdirs">
<mkdir dir="${build.dir}/dist" />
<mkdir dir="${build.dir}/lib" />
</target>
<target name="clean">
<delete includeemptydirs="true">
<fileset dir="${build.dir}/dist" includes="**/*"/>
</delete>
</target>
<target name="package-amp" depends="clean, mkdirs, package-jar" description="Package the Module" >
<delete file="${amp.file}" />
<zip destfile="${amp.file}" >
<fileset dir="${project.dir}/build" includes="lib/*.jar" />
<fileset dir="${project.dir}/config/alfresco/module/alfresco" includes="*.properties" />
<fileset dir="${project.dir}" includes="config/**/*.*" excludes="**/module.properties" />
<fileset dir="${project.dir}/source">
<include name="web/jsp/**/*.jsp" />
<include name="web/images/**" />
</fileset>
</zip>
</target>
</project>
I just tried going through the maven SDK tutorial that you suggested but I got
this error:
Feb 14, 2014 3:42:48 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
Check the build.xml file. Double-check the compile and package-jar tasks (or similar). For example, one or both of these tasks may have a fileset that uses a pattern to include your classes using the package structure, and it may no longer match now that you've changed your package name.
It's hard to tell without seeing your build.xml.
By the way, if you want a more up-to-date example for creating actions in Alfresco, take a look at this tutorial: http://ecmarchitect.com/alfresco-developer-series-tutorials/actions/tutorial/tutorial.html
It uses the Alfresco Maven SDK to package AMPs. The Alfresco Maven SDK is preferred over the old SDK you are using.

Applying Web.Config transformations outside of Web Deployment

Is there a way to apply VS 2010 Web.Config transformations outside of web deployment, say during debugging? It would give me a great boost to be able to freely switch between different environments.
Yes, you can perform a Web.config transformation explicitly by invoking the TransformXml MSBuild task during the AfterBuild step in your project file.
Here's an example:
<UsingTask
TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild" Condition="exists('Web.$(Configuration).config')">
<!-- Generates the transformed Web.config in the intermediate directory -->
<TransformXml
Source="Web.config"
Destination="$(IntermediateOutputPath)Web.config"
Transform="Web.$(Configuration).config" />
<!-- Overwrites the original Web.config with the transformed configuration file -->
<Copy
SourceFiles="$(IntermediateOutputPath)Web.config"
DestinationFolder="$(ProjectDir)" />
</Target>
Related resources:
Web.config transformations for App.config files
Can I specify that a package should be created every time I build a solution?
The solution above made a great starting point for me, but I ended up with the following which doesn't need a copy task and doesn't have any issues with file in use errors.
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
<TransformXml Condition="exists('$(TempBuildDir)\Web.$(Configuration).config')" Source="$(TempBuildDir)\Web.config" Destination="$(OutputPath)Web.config" Transform="$(TempBuildDir)\Web.$(Configuration).config" />
<ItemGroup>
<DeleteAfterBuild Include="$(OutputPath)Web.*.config" />
</ItemGroup>
<Delete Files="#(DeleteAfterBuild)">
<Output TaskParameter="DeletedFiles" PropertyName="deleted" />
</Delete>
<Message Text="DELETED FILES: $(deleted)" Importance="high" />
</Target>

ASP.NET Web Application (MVC) Deployment Automation and Subversion

We are trying to automate the build process to our staging servers but have run into a snag, albeit fairly minor. We are using the Publish functionality built into VS2010, committing to Subversion, and then a 3rd party app (Beanstalk) automatically pulls the updated files and FTPs them to the Staging server.
The problem we've run into is that we only appear to have the following choices:
(Lesser of 2 evils) If we choose to use "Replace matching files with local copies", this works great, with one exception: this option does not delete any files that were deleted from the project. This will lead to junk and/or security issues for unkempt files from the days of old.
If we choose to use "Delete all existing files prior to publish", this deletes the entire folder structure, including the .SVN hidden folders that Subversion uses for Update tracking, etc. This seems like the best solution from an accuracy standpoint, but it really destroys the local SVN environment, which is the middle-man for this automation.
My question: Is there an easy work around for this, or a totally different deployment option we're overlooking (we do not want to publish directly to the server from VS, as we want to track who/what/when a deployment takes place)? The only thing I've come across is to delete the file contents manually prior to publishing, while leaving the folder structure intact, then deploying with "Replace matching files with local copies". Unfortunately, this brings on a whole new meaning of the word "automation".
Any ideas on how best to accomplish this?
You may want to consider using NAnt or something similar for tasks you wish to automate, like building and publishing to Subversion. This is most of my build file for a WebApplication Project. It might be different for MVC. If so, I'm sure you can use this as a starting point. I am by no means an NAnt expert so there may be some flaws, but this is definitely working for me.
I had to add a PublishToFileSystem target to each .csproj file I wanted to publish. The source for that can be found here.
Build file also available on Pastebin
<?xml version="1.0"?>
<project name="deploy" default="all">
<property name="nant.settings.currentframework" value="net-4.0" />
<!-- Any of these can be passed through the command line -->
<property name="sourceDirectory" value="${project::get-base-directory()}" />
<property name="publishDirectory" value="${sourceDirectory}\build" />
<property name="MSBuildPath" value="${framework::get-assembly-directory(framework::get-target-framework())}\msbuild.exe" />
<!-- The build configuration to use when publishing and transforming the web.config file. This is useful when you have multiple environments for which you create builds -->
<property name="buildConfiguration" value="Release" />
<!-- Set these as needed -->
<property name="svn.username" value="" />
<property name="svn.password" value="" />
<target name="SvnPrep">
<property name="svn.dir" value="${publishDirectory}\.svn" />
<property name="svn.update" value="true" readonly="false" />
<echo>env.svn.path = svn</echo>
<echo>svn.dir = ${svn.dir}</echo>
<mkdir dir="${publishDirectory}" unless="${directory::exists(publishDirectory)}" />
<!-- Check if there's a .svn dir already. If not: checkout, else: update. -->
<if test="${not directory::exists(svn.dir)}">
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='co ${svn.builduri} --username ${svn.username} --password ${svn.password} --non-interactive ./' />
</exec>
<property name="svn.update" value="false" readonly="false" />
</if>
<if test="${svn.update}">
<exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
<arg line='up --username ${svn.username} --password ${svn.password} --non-interactive --force ./' />
</exec>
</if>
<!-- Force any conflicts to be resolved with the most recent code -->
<exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
<arg line='resolve --accept theirs-full -R ./' />
</exec>
</target>
<target name="DeleteFiles">
<!-- Delete only the files (retain directory structure) in the directory to which you are going to publish/build. NAnt excludes svn directories by default. -->
<delete includeemptydirs="false">
<fileset basedir="${publishDirectory}">
<include name="**/*.*" />
</fileset>
</delete>
</target>
<target name="Publish">
<!-- I know there's an MSBuild task, I don't know why I didn't use it, but this works. -->
<!-- Build and publish frontend -->
<exec program="${MSBuildPath}">
<arg line='"${sourceDirectory}\YourProject.csproj"' />
<arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
<arg value="/target:PublishToFileSystem" />
</exec>
<!-- Transform the correct web.config and copy it to the build folder. PublishToFileSystem doesn't transform the web.config, unfortunately. -->
<exec program="${MSBuildPath}">
<arg line='"${sourceDirectory}\YourProject.csproj"' />
<arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
<arg value="/target:TransformWebConfig" />
</exec>
<copy file="${sourceDirectory}\YourProject\obj\${buildConfiguration}\TransformWebConfig\transformed\Web.config" tofile="${publishDirectory}\YourProject\web.config" overwrite="true" />
</target>
<target name="SvnCommit">
<!-- add any new files -->
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='add --force .' />
</exec>
<!-- delete any missing files, a modification of this http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn -->
<!-- When there's nothing to delete it looks like this fails (to NAnt) but it is actually fine, that's why failonerror is false -->
<exec program='cmd.exe' workingdir="${publishDirectory}\" verbose="true" failonerror="false"
commandline='/C for /f "usebackq tokens=2*" %i in (`svn status ^| findstr /r "^\!"`) do svn del "%i %j"' >
</exec>
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='commit -m "Automated commit from build runner"' />
</exec>
</target>
<target name="ShowProperties">
<script language="C#" prefix="util" >
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
foreach (DictionaryEntry entry in project.Properties)
{
Console.WriteLine("{0}={1}", entry.Key, entry.Value);
}
}
]]>
</code>
</script>
</target>
<target name="all">
<call target="ShowProperties" />
<call target="SvnPrep" />
<call target="DeleteFiles" />
<call target="Publish" />
<call target="SvnCommit" />
</target>
</project>
We also deploy out of SVN and ran into the same problem. Our solution is to essentially branch the project for "significant" upgrades -- situations where we were adding and deleting files, not just fixing small bugs and making tweaks which you can usually handle by xcopy. Svn layout looks like:
--project
---production
----20100101
----20100213
[etc, etc]
Procedure-wise, it is pretty simple -- if there are big enough changes, check in build artifacts as appropriate.
Another thing you might want to try, especially if you cannot get your production bits to "switch" branches easily, would be to use something fancier such as powershell to execute the delete files command, that could filter out the *.svn folders.
I would say "fortunately" this brings a whole new meaning to the word automation :) What you're describing is knows as Application Release Automation, also sometimes called Deployment Automation. If you really want to know who did what and where, what was the outcome, etc. then you are looking for a product like Nolio ASAP (http://www.noliosoft.com). Please let me know if this helps, since from what you're describing, it seems like a perfect match.
+Daniel
Why are you publishing the site to a folder that is handled by Subversion?
The way I would do it is work directly with the files in the SVN handled folders. As soon as I commit anything, it gets pulled by beanstalk to the staging area. This way, files deleted are always deleted from the repo and you don't have to worry about that. Everything is always in sync.
If you feel that this is putting too many files to the staging area, you can still use scripts and Visual Studio commands to publish the site. But I'm not sure how well Beanstalk integrates with this scenario. I know CC.net and many other alternatives do.

Could not load definitions from resource flexTasks.tasks. It could not be found

I'm attempting to compile a Flex application from an ANT script, inside of Eclipse (CFBuilder, based on Eclipse), and I've run into this error:
Could not load definitions from resource flexTasks.tasks. It could not be found.
I haven't been able to find anything that gives directions on where this file (flexTasks.tasks) should be copied to, if it's needed at all. Some places indicate that it should be part of the flexTasks.jar file. I've tried two different things:
Copy the jar file into the ant/plugins/lib folder (and restart my CF Builder instance)
Specify the path to the jar in the classpath attribute, as suggested by the comment on this page
Neither helps me get past this error.
Here's my build script, for reference:
<project name="Tagging" default="compile-tagging" basedir=".">
<!-- setup flex compilation capability -->
<taskdef resource="flexTasks.tasks" />
<property name="flex.src" value="./src" />
<property name="flex.bin" value="./bin"/>
<target name="compile-tagging">
<mxmlc
file="${flex.src}/main.mxml"
output="${flex.bin}/main.swf"
keep-generated-actionscript="true">
<source-path path-element="${FLEX_HOME}/frameworks" />
</mxmlc>
</target>
</project>
Adam, I believe you need to tell taskdef where to look for the file. try keeping flextasks.jar in the same directory as your ant file (for now... you can move it later after you get it working).
then, you can do something like this:
<taskdef name="mxmlc" classname="WhateverTheTaskIsNamed" classpath="flexTAsks.jar" />
While not ideal, this code is working for me at the moment:
<project name="IOLTagging" default="go" basedir=".">
<!-- setup flex compilation capability -->
<property name="FLEX_HOME" value="C:/program files (x86)/Adobe/Adobe Flash Builder Beta 2/sdks/3.4.1/" />
<taskdef name="mxmlc" classname="flex.ant.MxmlcTask" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<taskdef name="html-wrapper" classname="flex.ant.HtmlWrapperTask" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<property name="flex.src" value="./src" />
<property name="flex.bin" value="./bin"/>
<property name="swf.name" value="main" />
<target name="go" depends="compile-flex" />
<target name="compile-flex">
<mxmlc
file="${flex.src}/main.mxml"
output="${flex.bin}/${swf.name}.swf"
debug="false"
keep-generated-actionscript="false">
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.library-path dir="${basedir}/libs" append="true">
<include name="*.swc" />
</compiler.library-path>
</mxmlc>
</target>
</project>
I had the same problem, and the reason was in lack of permissions to acces $FLEX_HOME/ant.
You can also put the flexTasks.jar in ~/.ant/lib directory
If you run ant -diagnostics you should see the jar in USER_HOME/.ant/lib jar listing
I think you should have solved this problem. just trying flexmonkey today and also got the same problem.
"Could not load definitions from resource flexTasks.tasks. It could not be found."
solution is to make sure the flexTasks.jar is included in the dir lib of your project workplace.
when I copied flexTasks.jar from flashbuild folder \ant\lib and built it again. the problem is fixed.

VBC + NAnt. Error compiling WinForm

It should first be noted that I am trying to avoid rewriting all my scripts to use msbuild.
I have noticed that there are several problems when using NAnt with the VBC task and compiling a WinForms application. The main problem seems to be that VBC can't find Sub Main. This is odd, since from within VS, there is no indication that there is any sort of difference between my call to vbc and msbuild's call to vbc.
Does anyone have any insight into a solution to this problem or a way to force the creation of the rest of the partial classes that might/might not be being produced by MSBuild/VS?
Sample Build Script:
<?xml version="1.0" encoding="utf-8" ?>
<project xmlns="http://nant.sf.net/release/0.85/nant.xsd" name="Test" default="build">
<target name="build">
<vbc target="winexe" output="C:\Test.exe" main="WindowAppNantTest.My.MyApplication" verbose="true" rootnamespace="WindowAppNantTest">
<imports>
<import namespace="Microsoft.VisualBasic"/>
<import namespace="System.Windows.Forms"/>
</imports>
<sources>
<include name="**/**/*.vb"/>
</sources>
</vbc>
</target>
</project>
Error(s):
[vbc] vbc : error BC30420: 'Sub Main' was not found in 'WindowAppNantTest.My.MyApplication'.
It appears like the problem is coming from the main and rootnamespace attributes. What happens when you switch them to be something like the following:
<vbc target="winexe" output="C:\Test.exe" main="MyApplication" verbose="true" rootnamespace="WindowAppNantTest.My">
<imports>
<import namespace="Microsoft.VisualBasic"/>
<import namespace="System.Windows.Forms"/>
</imports>
<sources>
<include name="**/**/*.vb"/>
</sources>
</vbc>
or something like the following:
<vbc target="winexe" output="C:\Test.exe" main="My.MyApplication" verbose="true" rootnamespace="WindowAppNantTest">
<imports>
<import namespace="Microsoft.VisualBasic"/>
<import namespace="System.Windows.Forms"/>
</imports>
<sources>
<include name="**/**/*.vb"/>
</sources>
</vbc>
I'm not sure if you mean you don't want to use msbuild within NAnt or if you don't want to switch to msbuild scripting wholesale.
If it is the latter, then my reply on your other post on the same topic is valid here as well.
You can use NAnt contrib (http://nantcontrib.sourceforge.net/) and use msbuild within your NAnt script.
The reference on the msbuild task is:
http://nantcontrib.sourceforge.net/release/latest/help/tasks/msbuild.html
And the pertinent snippet:
<target name="build" depends="clean">
<msbuild project="ProjectName.vbproj" />
</target>
What you need to do is set the following into your VBC command:
<references>
<include name="System.Windows.Forms.dll"/>
<indlude name="Microsoft.VisualBasic.dll"/>
</references>
This should fix your problem. (I guessed on the second dll as I'm a CS guy) however the syntax for compiling is pretty much the same.
In all the projects I've worked on you always need to set the references to include any DLL's whether they are from .Net, 3rd party or your own (ie Project references) otherwise they won't link in properly.
Give that a go and see what happens.

Resources