F# FAKE Get script directory - f#

Is there an easy way for me to get the path of the executing .fsx file using FAKE? Powershell and (psake) by nature of its use and MSBUILD provide this functionality but as FAKE/F# a noob it is not immediately apparent how to do this.

Try __SOURCE_DIRECTORY__ or
__SOURCE_FILE__.
It should work like in every other F# script file see F# for scripting: location of script file.

Related

Execute a recording from code on Ranorex

Does anyone know how to execute a recording file (rxrec) from code (I am using C#)?
I did look for examples and I couldn't find any.
Thanks!
In the standalone recorder (not in Ranorex Studio!!), you can export the recording to as an executable. You can call the EXE file in your code.
There is a Ranorex API for this. Just use this line of code.
NameOfYourRecording.Run();
I haven't tried yet, but you can execute a testcase through command line:
run outside ranorex IDE
So if you execute something similar in your C#, I guess it should do the trick. It's not really executing an rxrec file from your code, but result should be equivalent.
I assume that you want to execute the Ranorex recording from a different C# project.
You can compile your Ranorex project as ".dll" and then add reference to this dll in your other project.
After this you should be able to run any recording with {RecordingName}.Start().

FAKE equivalent to Ant properties files?

I'm converting a project from using NAnt to FAKE. The project is using a *.properties file to inform the main build.xml script of the locations of some executables that the build.xml script file will need to execute.
Due to the nature of these executables they are not easily discoverable because installation does not install them in PATH and the user is able to customize the location of where they are installed. Hence the *.properties files for users to set where they are located.
What would be the FAKE equivalent? I thought about having build parameters passed with each invocation of the FAKE build script but this isn't ideal because it requires them to remember what the build parameters are each time they want to run the build script. And having a build parameter be a long string which is the path to an executable is cumbersome to type each time anyway.
Thanks for any help.
As far as I know, FAKE does not have any built-in configuration system, but you can use any of the F# libraries for working with XML to read the configuration file. One nice option would be to use the XML type provider from F# Data.
You'd need to make sure the FSharp.Data package is restored before FAKE is run (in the same way in which you're downloading FAKE). Then you can write config.xml looking like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<temp-folder>C:\temp</temp-folder>
<executable>foo.exe</executable>
</configuration>
If you then add reference to F# Data and open the FSharp.Data namespace:
#r "System.Xml.Linq.dll"
#r "packages/FSharp.Data/bin/FSharp.Data.dll"
open FSharp.Data
You can then use the XML provider. This can actually pick the names of the XML elements and makes them accessible as properties, so you get really nice access to the config:
type Config = XmlProvider<"config.xml"> // Assuming this is in the same folder
let config = Config.GetSample()
config.Executable
config.TempFolder
Put the values for these custom paths in a .fsx file
Include this .fsx file in your main build script

Running a Rascal program from outside the REPL

I'd really like to be able to run some Rascal's program from outside the REPL (e.g. as part of a script, or called from another program). What I'm using Rascal for is and intermediate stage in a larger framework so I am wondering what the best way to go about integrating executing the Rascal code from another program.
Right now the best way is to package your code together with the Rascal shell executable jar. There is a convenience class JavaToRascal for calling into Rascal code. Sometimes it requires some thinking to add your own modules to the Rascal search path using IRascalSearchPathContributors, but if you include a RASCAL.MF file with the right properties it all should go automatically.
If you are thinking of an Eclipse plugin, then the best way is to let your plugin depend on the rascal-eclipse plugin and use ProjectEvaluatorFactory to get access to the interpreter.
Caveat: since we are moving to a compiled system, the code you write for this kind of integration will change. This is the reason we haven't documented the API for calling Rascal from Java yet.
As I was pondering the same question, this is the (maybe trivial) answer I came up with:
java -jar /path/to/rascal-shell-stable.jar path/to/myProgram.rsc
You have to be aware that Rascal calculates module names from the current directory (don't know if it supports something like Java's CLASS_PATH), so in the above example myProgram.rsc should have a module declaration of module path::to::myProgram. Calculated and declared module name have to match.

F# Interactive Developement DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Bob\AppData\Local\Temp\MyFolder\'

When using F# interactive apparently this line of code will search in the path shown in the subject line.
let files = Directory.GetFiles("MyFolderPath")
Is there any way to set interactive to search the same folder the current fsx file is running from? Or any way to control this behavior at all? I'm used to the search starting in bin\Debug obviously and this behavior is throwing me off.
Thanks in advance,
Bob
It depends from where the process fsi.exe is started. Fsi is separated from the IDE, it doesn't know which file is open. When you run Visual Studio, the current directory for fsi is the temp folder.
If you run the fsx file (fsi foo.fsx or right-click "Run with F# Interactive"), fsi will run from current directory.
To see where you are (in which directory), you can do:
Directory.GetCurrentDirectory()
To change directory, use this command:
Directory.SetCurrentDirectory(...)
F# interactive is completely independent of the current F# program (in fact, think of it as running in a separate CMD shell). So I'm afraid, there won't be a simple way to get the currently opened .fsx file.
You might be able to pull something from fsi.CommandLineArgs but I have no VS at hand to confirm this.

How to invoke PascalScripts UnitImporter from command line

I want to know if there is a way to start the PSUnitImporter.exe from command line. What I want to do is to have the import file created automatically as a Pre-Build Event.
So far I have found out that when running PSUnitImporter.exe "C:\folder\source.pas" it will invoke the Importer gui and automatically load the file. It will not do the conversion though and it shows the GUI which I don't want.
The gui itself isn't capable of doing that, however the source for the program is in svn at pascalscript project page. A few slight changes there will let you do what you want.
Thanks to CK who pointed me to the pascalscript projet page. I checked out the sourcecode there and found out that it already includes a project for a Commandline importer.
All I needed to do is compile this project and I was done. I wonder why this "CMDimp.exe" is not included in the Pascralscript setup.

Resources