0

I was wondering how I could use a file in my project that's not in my project. For example, after I compile I have something like below.

enter image description here

Inside the folder there is a file named "Class1.CS"

Ryan J. Smith
  • 1,140
  • 8
  • 15
  • does your project know how to use it...? You haven't really explained what your end goal is – Jonesopolis Apr 23 '15 at 16:35
  • Yes the project knows how to use it, currently its in the project but i want it moved to that folder so the user can edit it – Mike Donovan Apr 24 '15 at 16:51
  • You want a user to be able to actually edit your C# code? That's terrible. Whatever problem you're trying to solve, this isn't the right approach – Jonesopolis Apr 24 '15 at 16:52

2 Answers2

0

In Solution Explorer, you can right click the folder you want your file in, click Add > Existing Item > Class1.cs

Josh L.
  • 454
  • 2
  • 13
0

If you want run the c# algorithm dynamically on program run you have to compile it on the fly.

  1. you have to define some interface in your assembly
  2. do the interface implementation in your cs file (will be compiled later)
  3. in your assembly dynamically compile your cs file with reference to assembly with your interface type
  4. load assembly
  5. use reflection to instantiate the implementation of the interface
  6. run method on the interface

One possible solution is using CSharpCodeProvider mention in this answer or you can use Roslyn compiler like on this blog

Community
  • 1
  • 1
Aik
  • 3,528
  • 3
  • 19
  • 20