building c# with ant or nant

M

michael sorens

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.
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
M

michael sorens

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.
 
W

Walter Wang [MSFT]

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
<solution> which 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/articles/showarticle.tss?id=NAnt

#NAnt task: <solution>
http://nant.sourceforge.net/release/latest/help/tasks/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 ([email protected], 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.
 
B

Bruce Wood

Walter said:
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
<solution> which 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/articles/showarticle.tss?id=NAnt

#NAnt task: <solution>
http://nant.sourceforge.net/release/latest/help/tasks/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?
 
M

Markus Stoeger

Walter said:
If this concerns you, I recommend you to use NAnt, it has a task named
<solution> which can process a given solution file and compile the projects
contained within.

As far as I remember, NAnts <solution> task doesn't support VS2005 yet.
I haven't tried it with the latest version, but the docs still say the same.

Max
 
W

Walter Wang [MSFT]

My mistake, Thanks Max for pointing out. The latest NAnt version's
<solution> task currently still only supports VS2002 and VS2003 yet. Sorry
for the confusion.

--
Regards,
Walter Wang ([email protected], 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.
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
G

Guest

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?
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
M

michael sorens

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 <exec> task 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?
 
B

Bruce Wood

michael said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top