I've seen a lot of people talk about the Roslyn compiler and its ability to compile as a service. There's a feature in Java when developing in Eclipse (not sure if it's only Eclipse) that allows you to modify the code without stopping or pausing the application. This is really useful when debugging render in games (that's what I use it for). Will the new abilities that Roslyn brings allow such a thing in .Net development?
Will the new abilities that Roslyn brings allow such a thing in .Net development?
No, Roslyn is still mostly a traditional compiler: code comes in and an assembly (.exe or .dll) comes out.
What's different with Roslyn is that it lets you manipulate code. But it doesn't do anything regarding manipulating assemblies, which I think would be required for what you're asking.
Because of dynamic compilation we can just make the changes in the code and need to just refresh the browser to reflect our changes.In the previous versions of ASP.NET we have to make code changes then re-build the solution and then refresh the browser for our changes to take effect.
Now we can just change make the code change and refresh the browser for our change to reflect.
http://www.codeproject.com/Articles/835251/Overview-of-ASP-NET-vNext
Related
I'm looking for ways to "rewrite/tweak" C#-scripts in a Unity3d-project somewhere between me editing them in VS and the compilation before running/building the project in the Unity editor. I have seen that Roslyn Source Generators is possible to integrate in Unity, but I much much rather use a Roslyn Syntax Rewriter, if I could only find a way. It does not seem to be possible to integrate syntax rewriters in a normal .NET build in VS (it would have been awesome if it did though) but I was thinking that perhaps Unity have some hooks I could use instead? Perhaps when the script-resources are reloaded after being edited? I don't want to make the changes permanent though, but only visible for the build process. Any other hooks or hacks I could use here? If I only could get the script-text and transform it a little bit before the build... I would be so happy...
I think you are looking for IPreprocessBuildWithReport.OnPreprocessBuild which allows you to run anything just before a build starts.
Note though that if you modify any files in there it would probably still be permanent.
I think you can easily prevent this from happening by using version control and just reset after building ;)
Alternatively you could of course somehow store your changes (e.g. in copied temporary files) and revert in IPostprocessBuildWithReport.OnPostprocessBuild.
Or if you know what you are doing you could rather modify the precompiled assemblies in IIl2CppProcessor.OnBeforeConvertRun which wouldn't affect your c# source code files but rather only the built managed assemblies right before they are transcripted into c++
I'd like some help in how to add scripting support to a WPF C# project I'm doing on Visual Studio 2015. One of the things I'd like to do is to be able to change User Control properties within that script. I've being trying Roslyn C#, and I read some stuff about IronPython and PowerShell Tools. But, all that information is not really helping.
So, do you have a simple answer? Like, the easiest way to execute scripts in Visual Studio 2015 C# WPF Application, that are able to change properties of User Controls within the project?
Any help would be appreciated.
Thanks,
Lucas.
T4 templates can help but they are less extensible than lets say Roslyn.
I found a great post on how to easily implement IronPython and how to access User Controls within the scripts in Python, so you can there change different Control properties, and even create them! Here's the link:http://www.codeproject.com/Articles/602112/Scripting-NET-Applications-with-IronPython
I think it should be quite simple to embed powershell or F# interactive in an application and there are lots of examples when we search the web for this. The question is only are we comfortable writing scripts in Powershell and F#?
In my application I provide a C# editor and compile scripts as static methods (which I uses as functions) using the standard .Net compiler API's which are installed with the framework (Microsoft.Csharp, System.CodeDom). This generates a temporary dll and perhaps can not be properly termed a script. The implementation is straight forward and more or less what you expect - I have to provide a way for the users to specify references and namespaces, then generate a source file, compile it to an assembly and then call members of the static class. This above technique works well because the application has extension points that are well adapted to user defined code with a certain well defined structure (you might have similar well defined needs and perhaps full scripting is not necessary).
On the other hand, I am considering providing a "super user" console where the application can be driven by script, and in this case, I will use either Powershell or F-sharp interactive (I'm leaning towards F#). I don't think the implementation is particularly complex, but these are things that can easily bring the application down or corrupt application data if it is not well controlled - and it is unlikely that my users will profit from scripting as it is a programmer environment.
I'd like to give user the opportunity to do its own report based on my class hierarchy (object in memory). A scripting language like VBA: Visual Basic for Application. Something that would be evaluated at runtime.
I'd like the user to be able to dynamically create its own report based on some available restricted objects marked with specific attributes only. Give user possibility to create macro where he have similar model as in VBA-Excel : Application/Workbook/WorkSheet/Range/... but with my specific selected objects instead.
Then, he would have been able to use intellisense and add its own functionality to its application.
Update: There is something very important that appears to me. The editor should be preferably part of the application itself in order for the script to know all the environment (namespace, objects, ...) it should interact with. Otherwise, having a scripting engine/editor in a separate process would force the application to be either a "single-instance" app or to create a tricky way to hook the script to a specific running application process.
Does it exists and how to plug it to a .net app?
4 solutions have been proposed:
IronRuby
CsScript
WinWrap
Windows Scripting Host (WSH)
I also found:
ScriptCs
RoslynPad
Code Project - Anoop Madhusudanan article: C# as a Scripting Language in Your .NET Applications Using Roslyn
But I wonder which one could fits every needs (or most of them):
Editor with Intellisense
User have access the currently running process object model (Application as global and all its related objects accessed through application properties). Optional but very nice to have: not necessarily every public properties, only marked ones with specific attributes.
Interactive environment enabling step by step, debugging, breakpoints, ...
Editor/debugger Licensed for free redistribution
Not required, but preferably use C# language
Actual testing:
I tried to evaluate #2 but there is no VS project sample with all modules working together (which seems a little bit complex to assemble).
I currently evaluate #6 which seems to work fine (I corrected a minor bug). It seems to fits most points but #3. But it seems to be the closest to my needs yet. It also uses Roslyn which appears to me a positive aspect because it is the Microsoft compiler which should always be up to date.
I'm still waiting to see any feedback from anybody with either other better solutions or any advise to help me take a better decision.
After some thought, trials and errors. My needs become clearer and my understanding of to current state about Roslyn development was also better.
I realized that Oleg Shilo (Author of CS-Script) was right about the fact that Roslyn is not ready (2014-10-21) to help me for intellisense. But I think it should happen relatively soon. I think it should worth the wait. But it can compile and run code into the same running app I would like to run tested in.
Although any other approach could have probably work better right now. I think that a solution like RoslynPad would be closer to the ideal solution for my needs. Most other proposed solution where nice for general scripting but not as good as RoslynPad for inside app own scripting... at least according to my opinion.
I then fixed some little issues in RoslynPad and hook it to the newest AvalonEdit which also fixes some other issues with auto-completion (but still with few bugs).
I now get needs filled up as this:
#1 Partial (ready for full when Roslyn will supported and documented it)
#2 Full
#3 No (ready for full when Roslyn will supported and documented it)
#4 Full
#5 Full
Thanks a lots to all people giving me ideas, links and very nice advise.
I'm not sure if the title is accurately describing what I'm trying to ask...
Basically, how does Visual Studio look at a code file in a CSPROJ and determine references for a method or variable, or if a using statement is not being used in the code? Obviously it's not just doing simple text parsing, and it seems to work before ever doing a build so I don't think it's referencing the assembly/CLR.
Is there an API that I can tie into from an external app, if I have the user select their CSPROJ or SLN file and be able to report on unused using statements in files, or methods/vars that aren't being called anywhere in their code?
I'm asking because I'm considering building some sort of reporting tool to show areas where code cleanup could occur, but I'm not really sure where to begin.
Thanks!
EDIT: As a followup question, is there a similar tool already out there?
Visual Studio does compilation on the fly, in order to determine many of the things like this, in addition to providing functionality like Intellisense.
Right now, the compilers are all a "black box" and not directly usable. The Roslyn project has the goal of changing this, allowing the full breadth of code analysis being done to be usable. It's currently in a CTP, and could be used now.
EDIT: As a followup question, is there a similar tool already out there?
Many third party extensions, such as Resharper, provide much of this functionality (such as their Safe Delete refactoring and Solution Wide Inspections).
We currently use IronPython as a scripting language to allow our business users to configure large portions of our application and we are evaluating the possibility of adding in C# as a scripting language once Roslyn is released. For IronPython, we use Microsoft.Scripting.Hosting.CompiledCode to cache the compiled code and execute it against different ScriptScope object.
Looking around the latest Rosyln CTP I don't see an obvious way to compile code and then execute it against different Sessions or hostObjects. Is this functionality available at this time, and if not, is it going to be available at release?
We currently are looking at supporting the same scenario with the Roslyn Scripting APIs, that is, to compile the code so that you can execute it independently against different scopes. It will likely be a bit different than the DLR Hosting APIs, and by the time we ship, plans could completely change. I should post my updated scripting spec. I haven't done so already since we did not do much work on the Interactive/scripting area for CTP2, focusing ore on the compiler APIs. We have sketched out the direction we're thinking in regards to your question. I'll try to do that today, so on the Roslyn forum, see the pinned post at the top of the forum, which I'll update with a link to the updated spec.
Thanks,
Bill
I don't know a whole lot about Roslyn but it looks like this would accomplish what you're after. Loading an assembly generated by the Roslyn compiler