1

I am working on an integration test project where I have a local database inside the solution file of the project which on every compile gets copied to the 'bin/debug' which then is used.

Now, I have a requirement to only make changes to the database in the debug mode so that we do not make any changes to the original database and a large database file doesn't get pushed to source control.

I know that there is an option in Visual Studio that results in changing data only to the database in the bin folder while the original database stays intact, I want something exactly like that.

also, I just need to copy the original database to the bin folder only on first build (when there is no .mdf in bin)

Properties for database file in Visual Studio are as follow:

Content > Copy Always

My connection string is this:

<add name="MaxDatabase" connectionString="Data Source=(LocalDb)\ProjectsV13;Initial Catalog=Catalog=MaxLocalEmbeded;Integrated Security=SSPI" providerName="System.Data.SqlClient" />

I need something like the OP's problem here: https://stackoverflow.com/a/17147460/5360889

Any help with this will be highly appreciated. Thanks!

Zeeshan Adil
  • 1,937
  • 5
  • 23
  • 42
  • 1
    If I understand your problem correctly then you could change the MDF property to Copy Never and add a pre-build script to your project file to copy the file to the bin\debug folder only if it doesn't exist – Steve Oct 12 '19 at 13:14
  • https://learn.microsoft.com/en-us/visualstudio/ide/specifying-custom-build-events-in-visual-studio?view=vs-2019 – Steve Oct 12 '19 at 13:17
  • 1
    @Steve Thanks a bunch for pointing me to a right direction, I wrote the build scripts and it worked like a charm, please put this comment as an answer so more people may get help from it, Thanks again. – Zeeshan Adil Oct 13 '19 at 17:22

1 Answers1

2

If I understand your problem correctly then you could change the MDF property to Copy Never and add a pre-build script to your project file to copy the file to the bin\debug folder only if it doesn't exist –

enter image description here

Of course you could simply call a batch file from the same window, passing some of the predefined macros and write very complex pre or post behaviors for each of your project files in your solution.
However, when using a batch file, as specified in the note in the previous link, don't forget to prepend the name of the batch file with the keyword call

Steve
  • 213,761
  • 22
  • 232
  • 286