Build script with C# - c#

For insight into the below, read: http://martinfowler.com/articles/rake.html
I've been using Rake (with Albacore) recently, and like it alot. Mostly the strength of having the Ruby language right at hand when I need it.
I must admit I am alot more at home with C# - and that lead me to thinking if there was an equivalent to Rake in the .NET world.
What I am looking for is a way to write build scripts in C#, or maybe a DSL, having the same dependency programming model, where I can also use C#.
Maybe I'm way off base asking this question. But if it's possible to do with Ruby (and an internal DSL), then I can't right off the bat say why the same wouldn't be possible for C#. And I certainly don't understand why it hasn't already been done :-)
Anyone have some perspectives on the issue?
What we already know:
C# needs to be compiled to run, so we would need to create a seperate build-script, that is parsed, and compiled at run-time by an executable.
Thanks in advance!
Solution
Use "Cake" http://cakebuild.net/ -- with Roslyn compiler what I wanted (years ago) is now possible. Thanks Microsoft. And thanks to the people who wrote Cake.
An alternative is to use Powershell. The library is called Psake (saké)

Maybe Cake is what you're looking for: https://github.com/cake-build/cake

A lot of people do use Rake for build scripts. There are even Rake tasks just for .NET. http://albacorebuild.net/
But there is a c# based make utility I know about. http://shake.codeplex.com/ And I thought I saw one on github. But I think they require a compile and that didn't seem as cool.
I ended up on https://github.com/psake/psake mainly because I wanted to learn Powershell and everyone already had it installed.
Hmm Bounce too https://github.com/refractalize/bounce

You can script your build/deployment tasks with msbuild and then script your tasks and execute them from bat files.

Related

How to use python code to create a universal windows platform application?

Converting python to C# is an option. Are there any ready-made converters to do this? Or are there any other ways to realize a uwp app from a python code? You help is very much appreciated.
There is a command line tool available on GItHub for this -
https://github.com/uxmal/pytocs
By the way you should ask these type of question first to google :P
There is IronPython, which is .NET implementation of Python 2.7 (http://ironpython.net/). I would venture if you start your Main() function as C# code, but transfer control to embedded IronPython interpreter, and continue with Python, it might work. Not all Python library would be available, I believe, due to sandboxing requirements of the UWP.
I think your best bet would be converting, and then learning a little. Based on the difficulty and how many different or new things you need to learn to alter the app, you should maybe just consider learning the language basics and then go from their creating it in C#, You'll gain some skills in another language. Who knows maybe like it more.
You could try one of many other converters, to another language that works or even convert to a language to convert. There is a C++ converter of some kind that may be a bit better, and then I guess perhaps you could convert from their with other tools, seriously may work better. More things are out their for C++ than C# and considering the commonalities, I bet a decent converter exists. Maybe convert to C or C++ or even Javascript because they have good conversion tools. With Java Script it would be kind easy to convert and learn a tiny bit to fix if you have a converter to C#.
Otherwise converter between the two Python and C# isn't a main priority for many people, if anyone at all. Since they are so similar yet the Syantax is so different, it must be hard to create, and usually people stick with one or the other, or learn both because they do a lot of Object Oriented Code. I mean just Syntax needs to be learned. Also the modules mentioned or packages probably wont ever convet to C#. I'm pretty sure they would just need to build the packages from the ground up for C#, witch is possible.
Is Python able to build universla windows apps?
The short answer: just for IOT devices. And the suggested programming language are C++, C#, Microsoft Visual Basic, and JavaScript within UWP. You could only build Python-based background applications on Windows 10 IoT Core devices with pyuwpsdk.vsix.

Some questions regarding implementation of a scripting engine

Since this would be hard to explain, let me start with a Diagram:
So much for the theory, but how would I actually implement this? Is this even possible/feasible?
Some questions that come to mind:
How would I actually load the scripts into Objects for the ScriptManager to hold?
How do I expose certain functionality? I don't want them to have ultimate power over my program, only one Domain.
How would the scripts even know about for example EngineClass? Should I do a using in the scripts? Wouldn't that require to be copy of the assembly in the script path?
I heard about MEF, is this possible? It seems more fitting for plugins.
How do I even compile the scripts?
Of couse I understand you can't answer all of those or implement the whole engine for me. But I need pointers on what to do, I've been banging my head on this concept for a long time.
Thanks in advance for any answers.
After some more researching I stumbled upon What is the best scripting language to embed in a C# desktop application? and http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx and it seems to do what I want with some modifications. How I didn't stumble on this the weeks before I don't know.

C# Script version of PyBinding for WPF

I wrote a CSharpScriptBinding roughly equivalent to the PyBinding on CodePlex. It uses the C# script engine from http://www.csscript.net.
After I wrote it, I kind of decided it might not really be something good to use. Although it caches the compiled script code as an already compiled Assembly, my concern is that I will have one temporary Assembly created each time I use the binding. Will this add up to a problem in the future? If so, maybe there is a way in the C# script engine that I don't know about to optimize this further...? Any thoughts to confirm my suspicion that this was just a bad idea (but useful excersise in learning more about bindings and converters)?
Ask them if they use the DLR? Without it, I wouldn't trust it.

Is it possible to load and execute C# snippets using DLR?

The majority of material I have found regarding DLR is related to IronPython. Can you parse and execute C# using DLR? If so is there over head that would prevent you from attempting this on a web server with about 30 users?
More specifically I would like to script the configuration of my workflow objects when a user first initiates a workflow. Depending on conditions that change through out the year workflows may start at different steps, hence running configuration scripts seems like a good way to handle the variation.
It sounds like you're really talking about the C# "compiler as a service" (at the end of this video), which will hopefully be in the 5.0 timescale for .NET (although Mono has it now). For now, CSharpCodeProvider is the best we have (which works largely like "csc").
Although Marc offered an alternative for me, I read this related SO question and C# and VB are not supported as of yet.
You may find this relevant...though it doesn't run on the DLR itself.
Mono Compiler as a Service (MCS)
It has the advantage of running snippets and not loading a new assembly on every compile like CodeDom does.

What's a good way to write batch scripts in C#?

I would like to write simple scripts in C#. Stuff I would normally use .bat or 4NT .btm files for. Copying files, parsing text, asking user input, and so on. Fairly simple but doing this stuff right in a batch file is really hard (no exceptions for example).
I'm familiar with command line "scripting" wrappers like AxScript so that gets me part of the way there. What I'm missing is the easy file-manipulation framework. I want to be able to do cd(".."), copy(srcFile, destFile) type functionality.
Tools I have tried:
NANT, which we use in our build process. Not a good scripting tool. Insanely verbose XML syntax and to add a simple function you must write an extension assembly. Can't do it inline.
PowerShell. Looks great, but I just haven't been able to switch over to this as my primary shell. Too many differences from 4NT. Whatever I do needs to run from an ordinary command prompt and not require a special shell to run it through. Can PowerShell be used as a script executor?
Perl/Python/Ruby. Really hate learning an entirely new language and framework just to do batch file operations. Haven't been able to dedicate the time I need to do this. Plus, we're a 99% .NET shop for our toolchain and I really want to leverage our existing experience and codebase.
Are there frameworks out there that are trying to solve this problem of "make a batch file in C#" that you have used?
I want the power of C#/.NET with the immediate-mode type functionality of a typical cmd.exe shell language. Am I alone in wanting something like this?
I would try to get over the PowerShell anxiety because it is the shell of the future. All of the software coming out of Microsoft is using it as their management interface and especially version 2.0 is ridiculously useful.
I'm a C# developer most of the time but PowerShell has solved that whole "WindowsApplication42" problem of temp projects just piling up. PowerShell gives you full access to the .NET framework in a command line shell so even if you don't know how to do something in PowerShell, you most likely know how to do it in .NET.
IronPython and IronRuby do let you leverage all of your .NET "experience and codebase" (they don't answer your objection to learning new languages, however).
If you have any bash nerds, you can always try cygwin.
Also remember that Python was originally intended as a "glue" langauge. If you used the aforementioned IronPython, it's pretty easy to tie together pre-written C# classes.
If you are bind to MS, PowerShell is surely the way to go. But I don't like it much.
I personally use MSBuild script more, and would like to see Mono C# Shell one day comes to Windows.
I think CS-Script might be the ideal solution for you.

Categories

Resources