In my NAnt project, I'd like to fire off a batch file and just forget about it. So I tried pulling something like this:
<exec program="start" commandline="cmd /c c:\mybat.bat" />
But NAnt complains:
'start' failed to start
The system cannot find the specified fileBlockquote
start cmd /c c:\mybat.bat works if I run it straight from the command line. Ideas?
Take a look at this AsyncExec task. Also, IIRC start is not a real program but a command, which is why you're getting that error.
A simpler alternative to use it the:
<exec ... pidproperty="pid1" spawn="true" />
<exec ... pidproperty="pid2" spawn="true" />
<exec ... pidproperty="pid3" spawn="true" />
<waitforexit pid="${pid1}" />
<waitforexit pid="${pid2}" />
<waitforexit pid="${pid3}" />
See NAnt exec task and NAntContrib waitforexit task
Related
In my demo project's build event, (a class library project), to copy the build result .dll to a specific folder, (auto-created if it doesn't exist), I added following command line in Post-build event command line section:
xcopy /Y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)DemoApp\bin\$(ConfigurationName)\Packages\"
It works perfectly.
Then I tried to replace that command line with a call to a new batch file called CopyPackage.bat located in $(SolutionDir). The content of the batch file is exactly the command line above:
call $(SolutionDir)CopyPackage.bat
Then I rebuild the project and get following error:
Severity Code Description Project File Line Suppression State
Error The command "call C:\TestProjects\DemoApp\CopyPackage.bat" exited with code 4. DemoApp
Do I miss something?
The solution after getting some hints from you all:
In post-build event command line I put: (see the params)
$(SolutionDir)CopyPackage.bat "$(TargetDir)$(TargetFileName)" "$(SolutionDir)DemoApp\bin\$(ConfigurationName)\Packages\"
In batch file CopyPackage.bat :
set targetfile=%~1
set targetdir=%~2
echo %targetfile%
echo %targetdir%
xcopy /Y %targetfile% %targetdir%
No need to use call you can simply invoke the batch script directly.
I do have to caution you, since the post-build targets have no way of knowing the inputs and outputs of the task, it will always have to execute the script, even if nothing has changed.
Instead, if you convert this to a msbuild target and you implement the input/output signalling correctly, you'll gain a lot of time by being able to leverage the incremental build features of MsBuild.
For example:
<Target Name="CopyOutputs"
Inputs="#(BuiltAssemblies)"
Outputs="#(BuiltAssemblies -> '$(OutputPath)%(Filename)%(Extension)')">
<Copy
SourceFiles="#(BuiltAssemblies)"
DestinationFolder="$(OutputPath)"/>
</Target>
More information on incremental builds and input/output signalling can be found:
MsBuild: transforms
MsBuild How-To: build incrementally
Extend the build process
call is an internal command of cmd.exe you should use
cmd.exe /c "$(SolutionDir)CopyPackage.bat"
instead.
Edit:
The content of the batch file is exactly the command line above
VS variables will not be properly resolved inside of the .bat file. You should pass them as parameters to batch file.
Changing the path in your CopyPackage.bat to absolute path can help resolve this.
Properties like these: $(TargetDir),$(SolutionDir) are recognized by msbuild.exe tool since they are part of msbuild properties and are defined or imported into current environment.
When using xcopy /Y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)DemoApp\bin\$(ConfigurationName)\Packages\" in post-build-event,the msbuild tool can recognize them.So for the first time, it succeeds.
However, for the second time. The msbuild engine can recognize properties in post-build-event, so it calls the .bat successfully. But since the .bat can't recognize the Msbuild property(These properties can only be recognized by MSbuild.exe, not .bat or cmd.exe), the build will fail for not finding the path.
I have a .proj file (build.proj) that I'm calling using a .bat (build.bat) file via the command window.
build.bat:
%SystemRoot%\Microsoft.NET\Framework\v3.5\MSBuild.exe projects\build.proj /fl1 /flp1:LogFile=build.log;Verbosity=Normal
From an elevated command window I run
> build.bat
It runs through build.proj all the way up until it tries to call another .bat file.
Here is the line in build.proj where it calls this .bat file (test.bat):
<Exec Command="call $(BatchDir)\test.bat />
$(BatchDir) is defined at the top of build.proj and equals "..\batch"
In the console output I can see that it is trying to call the batch file:
call ..\batch\test.bat
"The system cannot find the path specified"
test.bat definitely exists relative the the projects folder. What am I doing wrong here?
Directory structure:
/MyProject
build.bat
/projects
build.proj
/batch
test.bat
Try using the full path to test.bat in the $(BatchDir) variable.
It looks like it's taking .. relative to either %SystemRoot%\Microsoft.NET\Framework\v3.5\MSBuild.exe or /MyProject/build.bat, neither of which have a ..\batch directory.
I would like to ask if there is a more efficient way of running multiple transformations(70 transformations) besides the IDE? Doing it the IDE way is alright but it does become tedious having to click all the tabs and the hidden tabs as well.
What I did was I tried using the pan.bat command and placed it in a bat file. The bat file would look like this:
cd <to dest of kitchen.bat>
pan.bat <mytransformation 1>
pan.bat <mytransformation 2>
pan.bat <mytransformation 3>
pan.bat <mytransformation 4>
But it only works on the first transformation and then it quits. Am I doing something wrong or what options do I have to run multuple transformations from script
Thats what a JOB is for. Create a Job (or jobs) to run these transformations and execute with kitchen not pan.
You can also dynamically execute KTR's if you want to as well. i.e. execute all KTRs in a given folder etc.
Running via a job should be marginally faster too as you're not starting and stopping the entire VM every time. (which is surprisingly expensive)
Additionally running via a job gives you control over error handling, parallelisation and sequencing.
When calling a batch file from another, you have to use the call command, otherwise (as you found) it transfers control to the new batch file permanently.
call pan.bat <mytransformation 1>
call pan.bat <mytransformation 2>
call pan.bat <mytransformation 3>
call pan.bat <mytransformation 4>
Try this:
pan.bat "mytransformation 1"
.. or:
start /b "" "pan.bat" "mytransformation 1"
You can combine all transformations as a single or 2 jobs then call the job this is a efficiency way to call the all transformations in single job.
In pentaho by default jobs are running sequence mode if you want run parallel mode you can easily
I want to use ANT script to delete a file.
For some reason the following script gives me the following message:
BUILD SUCCESSFUL
Total time: 0 seconds
The script I am running is:
<?xml version="1.0"?>
<project name="UpdateFlag">
<target name="deleteFlag">
<delete file="/state/update.flag" failonerror="true"/>
</target>
</project>
Please assist.
<delete file="/state/update.flag" failonerror="true"/>
Will delete the file that's is in the state directory that's on the root of your directory structure. In Unix, it would be /state/update.flag, and in Windows (on the C: drive), it would be C:\state\update.flag. Is this where the file is located?
When in doubt, run Ant with the -d and -v switches. This will print out lots of useful information (and tons of useless garbage). For example, did your delete task find a file to delete? If the file isn't there, the <delete> task won't fail.
I have a funny feeling that you actually meant to do:
<delete file="${basedir}/state/update.flag"
failonerror="true"/>
How do I diff two files in MSBuild? I cannot find any specific task to do it.
If possible, is it also possible to exclude certain rows, or patterns in the files eg.
2009-12-09T10:03:07.6888125+02:00
You're gonna have to write your own MSBuild task which wraps some difftool commandline app. For commandline apps, you can inherit from the ToolTask class, which provides quite a bit of command line plumbing.
<Target Name="CheckFileSyncStatus" BeforeTargets="Build" Inputs="#(FilesToSync -> '..\..\..\folder1\folder2\%(Filename)%(Extension)')" Outputs="#(FilesToSync)">
<Exec Command="FC "%(FilesToSync.Filename)%(FilesToSync.Extension)" "..\..\..\folder1\folder2\%(FilesToSync.Filename)%(FilesToSync.Extension)"">
<Output TaskParameter="ExitCode" PropertyName="FCExitCode" />
</Exec>
<Error Text="[HP.OneDriver.Win10S.DriverProperties]:Files out of sync from source: %(FilesToSync.Filename)%(FilesToSync.Extension)" Condition="FCExitCode == 1" />