<!--
// NAnt - A .NET build tool
// Copyright (C) 2002 Gordon Weakliem
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

// Gordon Weakliem (gweakliem@yahoo.com)
-->
<project name="VSConvert" default="test" description="Converts a VS.NET project file (.csproj,.vbproj, or .vcproj) to NAnt format">
	<!-- usage:
	nant -buildfile:vsconvert.build -D:dir.src=[...] -D:dir.dest=[...] -D:filename.src=[...] -D:filename.dest=[...]
	-->
	<property name="dir.src" value=""/>
	<!-- should be a .csproj file -->
	<property name="filename.src" value="" />
	<!-- should be a .build file -->
	<property name="filename.dest" value="" />
	<property name="dir.dest" value="${dir.src}" />
	
	
	<target name="prepare">
		<mkdir dir="${dir.dest}"/>
		<property name="stylesheet" value="${nant.project.basedir}\VSConvert.xsl"/>
		<!-- set up defaults for the properties if they weren't specified -->
		<script language="C#">
			<code><![CDATA[
			public static void ScriptMain(Project project) {
				if (project.Properties["dir.src"].Equals(String.Empty)) {
					project.Properties["dir.src"] = System.IO.Directory.GetCurrentDirectory();
				}
				if (project.Properties["dir.dest"].Equals(String.Empty)) {
					project.Properties["dir.dest"] = project.Properties["dir.src"] ;
				}
				if (project.Properties["filename.src"].Equals(String.Empty)) {
					// look for candidate project files in the source directory
					string[] filelist = System.IO.Directory.GetFiles(project.Properties["dir.src"],"*.??proj");
					if (filelist.Length == 1) {
						project.Properties["filename.src"] = System.IO.Path.GetFileName(filelist[0]);
					}
				}
				if (project.Properties["filename.dest"].Equals(String.Empty)) {
					project.Properties["filename.dest"] =
						System.IO.Path.GetFileNameWithoutExtension(project.Properties["filename.src"]) + ".build";
				}
			}
			]]></code>
		</script>
	</target>
	
	<target name="convert" depends="prepare">
		<style in="${filename.src}" 
			basedir="${dir.src}"
			out="${filename.dest}"
			destdir="${dir.dest}"
			extension="build"
			style="${stylesheet}"
			>
		</style>
	</target>
	
	<target name="test" depends="convert">
		<nant buildfile="${dir.dest}/${filename.dest}" target="build" verbose="true"/>
	</target>
	
	<target name="save">
		<!-- TODO: add to VSS -->
	</target>
</project>