468,765 Members | 1,368 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

building c# with ant or nant

So I have compiled a .dll file from a Visual Studio 2005 project
containing a few dozen c# files. Now I want to automate this build using
ant (have not yet looked at nant, but the rest of my complex build is done
with plain ant). Could someone point me to any tutorial or other guide for
doing this? I would even settle for just how to do it from a command-line.
Jul 6 '06 #1
12 18346
http://www.baccoubonneville.com/blog.../nant-tutorial

I would also recommend Expert .NET Delivery using Nant.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"michael sorens" <m_********@community.nospamwrote in message
news:op***************@spo-cont-2-dt.itron.com...
So I have compiled a .dll file from a Visual Studio 2005 project
containing a few dozen c# files. Now I want to automate this build using
ant (have not yet looked at nant, but the rest of my complex build is done
with plain ant). Could someone point me to any tutorial or other guide for
doing this? I would even settle for just how to do it from a command-line.

Jul 7 '06 #2
Thanks Greg for your informative input.

Hi Michael,

Thank you for your post.

Besides Greg's suggestion on using NAnt, you can use ANT to build VS2005
project:

#ANT .NET Tasks
http://ant.apache.org/manual/OptionalTasks/dotnet.html
You can use "Csc" task to build your C# project, but it requires you to
re-specify included C# source files and referenced libraries.

Another option is to use ANT Exec task
(http://ant.apache.org/manual/CoreTasks/exec.html) to call Devenv.exe:

#Devenv Command Line Switches
http://msdn2.microsoft.com/en-us/library/xee0c8y7.aspx
You can use "/Build" switch to build an existing Visual Studio 2005
solution or project.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 7 '06 #3
Thanks Walter. These are good documentation pointers. From your
information, I observe that while the DotNet tasks in ant provide "native"
support in a sense, they require one to specify the architecture of the
build, which is already available in the solution file. So adhering to the
Good Programming Practice of laziness, it looks like using the ant exec
task to invoke devenv, which can directly use the solution file, would be
the simplest to implement.

On Fri, 07 Jul 2006 01:19:19 -0700, Walter Wang [MSFT]
<wa****@online.microsoft.comwrote:
Thanks Greg for your informative input.

Hi Michael,

Thank you for your post.

Besides Greg's suggestion on using NAnt, you can use ANT to build VS2005
project:

#ANT .NET Tasks
http://ant.apache.org/manual/OptionalTasks/dotnet.html
You can use "Csc" task to build your C# project, but it requires you to
re-specify included C# source files and referenced libraries.

Another option is to use ANT Exec task
(http://ant.apache.org/manual/CoreTasks/exec.html) to call Devenv.exe:

#Devenv Command Line Switches
http://msdn2.microsoft.com/en-us/library/xee0c8y7.aspx
You can use "/Build" switch to build an existing Visual Studio 2005
solution or project.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
Jul 7 '06 #4
Hi Michael,

Thank you for your quick reply.

After written my last post, I've done some more research on this.

While directly executing Devenv.exe is simplest, it does have two
drawbacks:
1) The overhead cost of running Visual Studio 2005 is quite large;
2) Not all machines that need to build the project will have Visual Studio
2005 installed.

If this concerns you, I recommend you to use NAnt, it has a task named
<solutionwhich can process a given solution file and compile the projects
contained within. It recognizes inter-project dependencies and compiles
them in the correct order. And it does not invoke devenv.exe, but rather
parses the solution file and invokes the command-line compiler. You can
find more information here:

#Managing .NET Development with NAnt
http://www.theserverside.net/tt/arti...le.tss?id=NAnt

#NAnt task: <solution>
http://nant.sourceforge.net/release/.../solution.html

Since you've already written your ANT build file, you can only create a
simple NAnt build file for your Visual Studio 2005 project and call NAnt
from ANT.

Hope this helps. Please feel free to post here if anything is unclear.

--
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jul 7 '06 #5

Walter Wang [MSFT] wrote:
Hi Michael,

Thank you for your quick reply.

After written my last post, I've done some more research on this.

While directly executing Devenv.exe is simplest, it does have two
drawbacks:
1) The overhead cost of running Visual Studio 2005 is quite large;
2) Not all machines that need to build the project will have Visual Studio
2005 installed.

If this concerns you, I recommend you to use NAnt, it has a task named
<solutionwhich can process a given solution file and compile the projects
contained within. It recognizes inter-project dependencies and compiles
them in the correct order. And it does not invoke devenv.exe, but rather
parses the solution file and invokes the command-line compiler. You can
find more information here:

#Managing .NET Development with NAnt
http://www.theserverside.net/tt/arti...le.tss?id=NAnt

#NAnt task: <solution>
http://nant.sourceforge.net/release/.../solution.html

Since you've already written your ANT build file, you can only create a
simple NAnt build file for your Visual Studio 2005 project and call NAnt
from ANT.
Since this discussion is about VS2005 (which I'm not using yet, so I
have no firsthand experience), I'm surprised that nobody has yet
mentioned MSBuild. Isn't MSBuild based on the same principles as Ant
and NAnt? Is there no way to invoke MSBuild from Ant, rather than
firing up the entire Visual Studio just to do a build?

Jul 7 '06 #6
Walter Wang [MSFT] wrote:
If this concerns you, I recommend you to use NAnt, it has a task named
<solutionwhich can process a given solution file and compile the projects
contained within.
As far as I remember, NAnts <solutiontask doesn't support VS2005 yet.
I haven't tried it with the latest version, but the docs still say the same.

Max
Jul 8 '06 #7
My mistake, Thanks Max for pointing out. The latest NAnt version's
<solutiontask currently still only supports VS2002 and VS2003 yet. Sorry
for the confusion.

--
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jul 8 '06 #8
Thanks Bruce for your input.

I should have mentioned that MSBuild can be used to build VS2005 solution
or project files without Visual Studio 2005 installed. Normally you can
find MSBuild.exe at %windir%\Microsoft.NET\Framework\<v2_version>.

#MSBuild Command Line Reference
http://msdn2.microsoft.com/en-us/library/ms164311.aspx

--
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jul 8 '06 #9
Thanks, Walter, for mentioning the overhead of devenv; that is significant.
So if NANT does not yet support VS2005, then am I correctly inferring that
the msbuild suggestion (invoking in ant via exec task) would be able to use
the solution file and avoid the overhead of firing up VS?
Jul 8 '06 #10
Hi Michael,

Thank you for your update.

Actually MSBuild is included in .NET Framework 2.0 Redistribution Package
and runs without Visual Studio 2005. It can build VS2005 solution or
project files out of the box.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 10 '06 #11
Yes, I understood from the thread that MSBuild does not need VS2005. I was
getting back to my original question--integrating a build of a VS Project
into an existing Ant build. And what I last inquired about I have now
implemented. That is, all it took was a couple lines in my ant file doing
an <exectask with msbuild and my project file. I observe that msbuild
does handle conditional rebuild as well, so I did not have to add any
conditionals in ant.

[
If you are curious, here are two different snapshots of the build process
I use for my open-source web site and download libraries, auto-generated
from the ant file; the pictures show my C# documentation step but not the
C# compile step just discussed.
http://cleancode.sourceforge.net/arch/ant/ant_all.png
http://cleancode.sourceforge.net/arch/ant/build.png
]

The msbuild tool seems very much like ant or nant; assuming nant came
after msbuild, I am wondering what msbuild is lacking that drove the need
for nant?
Jul 10 '06 #12
michael sorens wrote:
The msbuild tool seems very much like ant or nant; assuming nant came
after msbuild, I am wondering what msbuild is lacking that drove the need
for nant?
You have the chronological order backward. NAnt was built to address
the lack of a build system for .NET outside of the Visual Studio
environment. Microsoft cribbed from NAnt (says me) and came out with
MSBuild only in the VS2005 release (.NET 2.0).

So NAnt predates MSBuild.

Jul 10 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by HaukiDog | last post: by
1 post views Thread by Chua Wen Ching | last post: by
3 posts views Thread by Me | last post: by
4 posts views Thread by SenthilVel | last post: by
11 posts views Thread by Mike Schilling | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.