2

I have a Visual Studio project in one folder, say C:\project_name\app_name.csproj and it has a structure like C:\project_name\controllers. I want to tell this project file to always look into a carbon copy structured folder, say C:\custom_project_name\controllers\ to see if there are any files in there, and, if so, override what is in the base project. This would not compile the customized file in the base project. It would instead use teh custom project's version of the same named file.

Is this possible? Sorry in advance if this is somehow a duplicate, but I do not even know what to call this when searching for an answer out there.

Skysmithio
  • 91
  • 1
  • 4
  • Perhaps copy files in a pre-build step? https://learn.microsoft.com/en-us/visualstudio/ide/specifying-custom-build-events-in-visual-studio?view=vs-2019 – David Browne - Microsoft Aug 03 '19 at 16:56
  • 1
    msbuild allows a lot of things, so with a lot of customizations in csproj it is possible for sure (either by generating a new csproj, or at worst by some smart [copying](https://learn.microsoft.com/en-us/visualstudio/msbuild/copy-task) ). But as https://stackoverflow.com/a/57340362/3745022 says it is **definitely** not something that you want to do. Most probably the suggestion there is exactly what you need, but to be sure that it is not XY-problem, it would be better for you to explain what you are trying to achieve in the end. – Eugene Podskal Aug 03 '19 at 16:57
  • In the end I'm trying to use a customized version of a file instead of the base file. For instance, in the base file I might do say x = 1 and in the customized file x = 2. Because this is business logic and I need total separation of the files from the project to differentiate what belongs to base versus what belongs to the custom set it would need to function the way I described above. – Skysmithio Aug 03 '19 at 17:10

1 Answers1

1

I'm going to save you some nightmares later on and suggest that what you're (probably) really looking for is the Strategy design pattern.

This allows you to manage those custom implementations at compile time (or even at startup time) with cleaner code that is easier to maintain and easier to discover.

  1. Program your controllers to use injected dependencies for the customizable logic
  2. Leverage this inversion of control to provide default logic via the same interface
  3. Find, at startup time, any customized logic and "use" that instead thanks to IoC
clarkitect
  • 1,720
  • 14
  • 23