How to set a NAnt project's basedir to the current directory? - nant

I would like to use paths in multiple tasks without specifying the basedir attribute each time.
Unfortunately the following is not supported:
<project basedir="${directory::get-current-directory()}">
</project>

use (.) in like:
<project basedir=".">
</project>
so the basedir will be set to the directory of your build file.

Related

NuGet package targets - how to copy files to subfolder of target dir on build?

I'm trying to add two text files to my nuget package so that when the user of the package builds the project, one file is copied to the root of the build directory, but another file is copied to a subfolder of the root like this
\bin\Debug\ - 1.TXT
- SubFolder\ - 2.TXT
This directory structure is a requirement of the assemblies in the package which will be looking for those files in those particular locations at runtime.
Based on this https://stackoverflow.com/a/30386836/1462656
and this https://stackoverflow.com/a/44752745/1462656
I am able to create a targets file that copies 1.txt to the root, but when I add the package to a project and build it, it just copies 2.txt to the root. I created a build folder as follows
And my targets file looks like this
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)1.txt">
<Link>1.txt</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)SubFolder\2.txt">
<Link>2.txt</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
How do you get it to create the SubFolder and copy the file to that folder?
Initially I was using the content folder to add my content files with subfolders to the nuget package, but I found that although the files were added with the correct directory structure to the solution itself, the files were added with attributes set to 'Do Not Copy' so they were not copied to the build directory - so I switched to the above approach instead. Is there a way to combine the two approaches?
I think I solved it using the following
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<RequiredFiles Include="$(MSBuildThisFileDirectory)**\*" />
<None Include="#(RequiredFiles)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Based on a solution found here https://stackoverflow.com/a/30316946/1462656

error while building project using Nant

I have file pro.build:
<?xml version="1.0" ?>
<project name="NAnt.NUnit2ReportTasks" default="build" basedir=".">
<sysinfo />
<target name="nunitreport">
<nunit2report out="HTML_TestResults.html">
<fileset>
<includes name="NUnitTestResult.xml" />
</fileset>
</nunit2report>
<echo message="HTML Test report generated." />
</target>
</project>
From command prompt(DOS), I am giving command,
Nant -buildfile:pro.build
But I am getting error
Target 'build' does not exist in this project
Can you help me resolving this?
With <project>'s default attribute you specify the target which should be executed if no other target is specified on the command line.
Problem: On the command line you're calling Nant -buildfile:pro.build so you are not specifying a target there. NAnt tries to execute default target build which is not present and fails.
Solution: Either you specify target nunitreport on the command line by calling Nant -buildfile:pro.build nunitreport. But since specifying a non-existent default target in your build file doesn't make much sense, I would suggest changing the default target:
<project name="NAnt.NUnit2ReportTasks" default="nunitreport" basedir=".">
<!-- ... -->
</project>
Specifing complete path for the buildfile could resolve the issue
nant –buildfile:"c:\FolderpathofAppdotbuildfileGoesHere\buildfilename.build"

How to Configure Rock Star Apps plugin in Eclipse for Concatenating and Compressing Javascripts

I am using the rockstarapps plugin for concatenating and compressing/minifying .js files with Google Closure.
I chose the option to rebuild files when a dependency changes but now I would like to change the dependencies, output file, etc... How do I do that?
What does the 'Add to Auto-Building' option do?
thank you,
DM
In the root of your project is an ant build file called .rockstarapps.
This is Xml and human readable.
The output file is specified near the top: <file name="path/to/file.js">
Auto Building: I assume this adds the file to the build section of .rockstarapps
The autobuilding option will only be activated if the files change, to add a new dependency, go to the .rockstarapps file and add up the line necessary, after saving just change some line into any of the dependencies and the file should be compiled with your new dependencies.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<rockstarapps>
<file name="WebContent/js/extlib.core.all.js">
<min>false</min>
<comp>false</comp>
<closureCompiler>false</closureCompiler>
<gZip>false</gZip>
<resolveImports>false</resolveImports>
<urlRewriting>false</urlRewriting>
<autoBuild>true</autoBuild>
<lineLength>-1</lineLength>
<autoTimestamps>false</autoTimestamps>
<removeLogs>false</removeLogs>
<oldFileNames>false</oldFileNames>
<dependencies>
<file>WebContent/ExtLib/core/modernizr.tdm.js</file>
<file>WebContent/ExtLib/core/jquery-1.8.3.js</file>
<file>WebContent/ExtLib/core/custom-tdm-jqm.js</file>
<file>WebContent/ExtLib/core/jquery.mobile-1.3.0.js</file>
<file>WebContent/ExtLib/template/knockout-2.2.1.js</file>
</dependencies>
<properties/>
</file>
</rockstarapps>

how to encode in Ant

I have a test script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" basedir=".">
<echo encoding="UTF-8" file="test.txt">测试</echo>
</project>
When I open test.txt. I only see "??"
Something more weird. The script run with no problem using Eclipse Ant tool, but it has problem with command line.
Both Eclipse and cmd are using the same Ant lib.
Use this encoding :
<echo encoding="UnicodeLittleUnmarked" file="test.txt">测试</echo>
And you will get the correct result in your file.
I found the reason.
Before running the Ant script, I need to set a system property:
Set ANT_OPTS=-D"file.encoding=UTF-8"
Then
<project name="test" basedir=".">
<echo file="test.txt">测试</echo>
</project>
runs successfully even if there is no encoding in the echo.
Can anyone tells me why the original one doesn't work?

Nant Build Error-- Nested build failed

I have a HelloNAnt.build file inside the directory:
D:\third party components\nant\WhatThis
My nant exe is placed at
C:\Program Files\nant
So I cd to D:\third party components\nant\WhatThis, type in the following command line:
"C:\Program Files\nant\bin\nant.exe" HelloNAnt.build
I got a build failed error, saying target HelloNAnt.build does not exist in this project.
What actually went wrong?
The content of HelloNAnt.build:
<?xml version="1.0"?>
<project name="Hello World" default="hello">
<target name="hello">
<echo>Hello</echo>
</target>
</project>
You omitted the -buildfile option, which specifies the path to the buildfile that you want NAnt to run:
"C:\Program Files\nant\bin\nant.exe" -buildfile:HelloNAnt.build
However, in your case, you needn't provide any options at all. NAnt will search the current directory for a file with a .build extension and run it.