0

I am new to development and please don't mind if my question is not clear.

I want to create an application which allows users to update .cs files later on as per their requirement and run the application without the need of re-building or re-compiling solution.

For instance, I have written a Checking_Balance.cs and now I want to add another new class/ or update the current class to include another function.

How can I make it work if I create one using notepad and copying it to the folder ?

I hope the question is clear enough for you guys to understand. Thanks

DiplomacyNotWar
  • 31,605
  • 6
  • 57
  • 75
  • 2
    Without building the code, how will the computer understand? You know the differentiation between things by looking at them. But computer doesn't. Your code needs to be converted to a format understandable to the computer. That's what the build does. – T.kowshik Yedida Jun 23 '21 at 06:15
  • I've removed the WPF tag from the question as it doesn't seem directly related to what you're asking. – DiplomacyNotWar Jun 23 '21 at 06:16
  • You would have to write code within your application to compile the .cs file, and then it would become its own library in memory. This is potentially suitable for adding scripting functionality to your application, but it shouldn't be used for everyday development as a way of avoiding compiling the application. – DiplomacyNotWar Jun 23 '21 at 06:17
  • 1
    You should look up Dependency Injection. It's a way to add new components to an existing app. You need to compile the new components, but it is as simple as copying the new DLL files to the folder with the new app to allow them to be incorporated in the program. – Enigmativity Jun 23 '21 at 06:21
  • Thanks for your advise. Llama I believe you are pointing me to the right direction. But can you please provide some useful links where I can study and see how to achieve this ? Because I have seen lots of applications that allows you to write script and point to their location and then they trigger and run that script. – user3102147 Jun 23 '21 at 06:21
  • I want to exactly perform same action where I can provide script name, path etc and then my application runs that and let it apply changes to data in the DB or application depending on what's written in the script. – user3102147 Jun 23 '21 at 06:22
  • In this case, you may look at C# scripting : https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/january/essential-net-csharp-scripting You don't need to recompile each time, it's just done at runtime for you. – Jimbot Jun 23 '21 at 06:22
  • Does this answer your question? [How to execute code that is in a string?](https://stackoverflow.com/questions/4800267/how-to-execute-code-that-is-in-a-string), [Is it possible to dynamically compile and execute C# code fragments?](https://stackoverflow.com/q/826398/8967612) – 41686d6564 stands w. Palestine Jun 23 '21 at 06:24
  • Why not use a scripting language which is able to do this for you. PowerShell for example? – Stefan Jun 23 '21 at 06:25
  • Stefan because I have experience in C# .net applications. – user3102147 Jun 23 '21 at 06:27
  • https://www.youtube.com/watch?v=Kyd-5UzzU2A Can someone suggest me if this is right approach ? Because it looks very easy. – user3102147 Jun 23 '21 at 07:13

0 Answers0