Skip to content
Browse files
fix msbuild task
  • Loading branch information
bodewig committed Dec 16, 2005
1 parent f4cb2b3 commit 730b9df03f4768bb7df44812f9e361dcb8306c24
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 97 deletions.
@@ -15,32 +15,31 @@ <h2>Introduction</h2>


<p>The current version requires Ant 1.6.2 or later and may even
work better for a CVS build of Ant created from CVS HEAD.</p>
<p>This version requires Ant 1.6.2 or later. If you are running
Ant 1.7 or later you may want to use the latest version of this
library instead.</p>

<h2>Where is it?</h2>

<p>The source code for the library currently lives in the
developer sandbox in Ant's SVN - <a
<p>The source code for the library lives in Ant's SVN - <a
A binary can be found at <a
A zip file containing the docs is also <a

<p>Note that these are temporary locations and may change later.</p>


<p>Right now direct any feedback either directly to <a
href="">me</a> or the <a
<p>Please direct any feedback to the <a
href=" List">Ant
developer list</a>.


<p>If you are building this from sources, run the antlib target
and you'll get a file <code>dotnet.jar</code>. If you've
and you'll get a file <code>ant-dotnet.jar</code>. If you've
downloaded <code>dotnet.jar</code>, you are already ready.</p>

<p>There are several ways to use the tasks:</p>
@@ -51,7 +50,7 @@ <h2>Installation</h2>
&lt;pathelement location="YOUR-PATH-TO/dotnet.jar"/&gt;
&lt;pathelement location="YOUR-PATH-TO/ant-dotnet.jar"/&gt;
@@ -68,7 +67,7 @@ <h2>Installation</h2>
&lt;pathelement location="YOUR-PATH-TO/dotnet.jar"/&gt;
&lt;pathelement location="YOUR-PATH-TO/ant-dotnet.jar"/&gt;
@@ -97,7 +96,7 @@ <h2>Installation</h2>
or a variation thereof.

<li>Using Ant's autodiscovery. Place <code>dotnet.jar</code>
<li>Using Ant's autodiscovery. Place <code>ant-dotnet.jar</code>
into a directory and use <code>ant -lib
DIR-CONTAINING-THE-JAR</code> or copy it into
<code>ANT_HOME/lib</code> - and then in your build file, simply
@@ -127,7 +126,7 @@ <h2>Tasks</h2>

<li><a href="msbuild.html">msbuild</a> - execute the MSBuild build
tool, untested.</li>
tool of Microsoft's .NET framework 2.0.</li>

<li><a href="wix.html">wix</a> - execute the WiX toolset, untested.</li>

@@ -9,13 +9,19 @@ <h2><a name="dotnetexec">MSBuild</a></h2>


<p>Runs the MSBuild build tool presented at the 2003 PDC. This
task is completely untested as the developers have no access to
the tool, it has been implemented by looking at the docs only.</p>
<p>Runs the MSBuild build tool of Microsoft's .NET framework

<p>You can either use an existing build file or nest a build file
(snippet) as a child into the task. If you don't specify either,
MSBuild's default build file search algorithm will apply.</p>
<p>Unlike the nant task, this task doesn't support nested build
files. MSBuild requires a certain default namespace and there is
no easy way to write an XML file of that type within Ant 1.6.x -
without repeating code that is already present in Ant 1.7 or some
ugly hacks, that is. Use the Ant 1.7+ version of this antlib and
Ant 1.7+ if you want nested build file snippets, alternatively use
the echo task to write the build file (see example below).</p>

<p>If you don't specify a build file, MSBuild's default build file
search algorithm will apply.</p>

<table border="1" cellpadding="2" cellspacing="0">
@@ -50,13 +56,6 @@ <h4>property</h4>
value that specify name and value of a property that is to be
defined in the MSBuild invocation.</p>


<p>This element allows no attributes. You can nest a MSBuild build
file into it and MSBuild will be executed on that. You can also nest
a build file snippet instead and Ant will wrap the necessary MSBuild
<code>&lt;Project&gt; around it.</code></p>


<p>Let MSBuild search for a *.proj file in the (Ant) project's base
@@ -76,34 +75,24 @@ <h3>Examples</h3>

<p>Define a build file embeded into the task, let MSBuild execute the
echo target of that build file.</p>
<p>Define a build file embeded into an Ant build file, let MSBuild
execute the echo target of that build file.</p>

&lt;target name="echo"&gt;
&lt;Project DefaultTargets="empty"&gt;
&lt;Target Name="empty"/&gt;
&lt;Target Name="echo"&gt;
&lt;Task Name="Echo" Message="This is MSBuild"/&gt;

<p>Run MSBuild's Echo task (if there actually is one):</p>

&lt;Task Name="Echo" Message="This is MSBuild"/&gt;
&lt;tempfile property="ms.proj" suffix=".proj"/&gt;
&lt;echo file="${ms.proj}"&gt;&lt;![CDATA[
&lt;Project DefaultTargets="echo" xmlns=""&gt;
&lt;Target Name="echo"&gt;
&lt;Message Text="This is MSBuild"/&gt;
&lt;msbuild buildfile="${ms.proj}"
&lt;delete file="${ms.proj}"/&gt;

<p align="center">Copyright &copy; 2003-2004 The Apache Software Foundation. All rights Reserved.</p>
<p align="center">Copyright &copy; 2003-2005 The Apache Software Foundation. All rights Reserved.</p>
@@ -38,28 +38,17 @@

<target name="nested-file">
<property name="foo" value="bar"/>
<Project DefaultTargets="echo">
<Target Name="echo">
<Task Name="Echo" Message="foo is ${foo}"/>

<target name="nested-task">
<property name="foo" value="bar"/>
<tempfile property="ms.proj" suffix=".proj"/>
<echo file="${ms.proj}"><![CDATA[
<Project DefaultTargets="echo" xmlns="">
<Target Name="echo">
<Message Text="foo is ${foo}"/>
<msbuild buildfile="${ms.proj}"
<Task Name="Echo" Message="foo is ${foo}"/>
<delete file="${ms.proj}"/>

@@ -1,6 +1,6 @@
<?xml version="1.0"?>
Copyright 2003-2004 The Apache Software Foundation
Copyright 2003-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -14,11 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
<Project DefaultTargets="empty">
<Project DefaultTargets="empty" xmlns="">

<Target Name="empty"/>

<Target Name="echo">
<Task Name="Echo" Message="foo is ${foo}"/>
<Message Text="foo is $(foo)"/>
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -54,7 +55,7 @@ protected String[] getBuildfileArguments(File buildFile) {

protected String[] getTargetArguments(List targets) {
if (targets.size() > 0) {
StringBuffer sb = new StringBuffer("/targets:");
StringBuffer sb = new StringBuffer("/target:");
Iterator iter = targets.iterator();
boolean first = true;
while (iter.hasNext()) {
@@ -100,21 +101,9 @@ protected String[] getPropertyArguments(List properties) {
* Otherwise, fail.</p>
protected Element makeTree(DocumentFragment f) {
NodeList nl = f.getChildNodes();
if (nl.getLength() == 1
&& nl.item(0).getNodeType() == Node.ELEMENT_NODE
&& nl.item(0).getNodeName().equals("Project")) {
return (Element) nl.item(0);
} else {
Element p = f.getOwnerDocument().createElement("Project");
p.setAttribute("DefaultTargets", TARGET);

Element t = f.getOwnerDocument().createElement("Target");
t.setAttribute("Name", TARGET);

return p;
throw new BuildException("MSBuild requires build files to have"
+ " a certain default namespace, which"
+ " cannot be achieved with Ant prior to"
+ " Ant 1.7.");
@@ -56,9 +56,4 @@ public void testNestedFile() throws Exception {

public void testNestedTask() throws Exception {
if (getProject().getProperty("msbuild.found") != null) {
expectLogContaining("nested-task", "foo is bar");

0 comments on commit 730b9df

Please sign in to comment.