1

So in Visual Studio I have a project on GitHub with an mdf file in the app_data directory.

How do I deal with this .mdf file, with regards to source control and building?

Bad Solution 1 - Check-in an empty .mdf file

I can create a stub mdf and check it in. But I don't like this solution. Once I check it in, then every change it shows up as changed and I have to exclude the .mdf on every subsequent check-in. Worse, if I forget to exclude it, then I have to revert the check-in.

Bad Solution 2 - Leave the *.mdf file ignored

I can leave the mdf file ignored. But now when someone checks out my solution an clicks build, the build fails. It is pretty easy to manually create the SQL file. But only if you know that is what you are supposed to do. Also, many potential users/contributors might check out my open source project, click build, see it fails, and decide to move on.

Currently I am using Bad Solution 1.

Mediocre Solution 1 - Copy another checked in file

Check in an mdf file to somewhere in the project. Run a copy command. I might have to settle for this option. I am hoping from something that is just a script thought.

Better Solution - Prebuild action to build mdf if missing I am struggling to implement this solution.

In the pre-build action of a Visual studio project, I have this:

IF NOT EXIST "$(ProjectDir)App_Data\SqlRepository.mdf" (
    REM Command to create SqlRepository.mdf here
)

But Visual Studio is adding an *.mdf. There should be a script that will create the stub if the file is missing. What is Visual Studio doing?

So a valid answer will involve:

  1. mdf not checked in
  2. not a file copy of another checked-in file
  3. script builds mdf if not there
  4. Script is not overly complex
  5. Works with almost every other windows + visual studio environment
Rhyous
  • 6,510
  • 2
  • 44
  • 50
  • Were you able to solve this issue? I realize some time has passed, but what you're proposing is still valid. I have a specific requirement for a project that could greatly benefit from a script dropping a *.mdf file on build if it doesn't already exist. Thanks. – Josh Cronkhite Feb 11 '19 at 22:06
  • 1
    Not yet. I moved from Bad Solution 1 to Mediocre Solution 1. Nobody seems to know how Visual Studio creates an .mdf file or how to recreate it on the fly. If someone knows, I'm not finding it on Google seaches. – Rhyous Feb 13 '19 at 15:36
  • Thanks for the reply. For now, I'm simply using a SQL Data Project, seeding the data, and running on SQLLocalDB for development. If there's no real MDF solution (the way we desire it, that is) I will just create one manually and include it as a default for deployment. Fortunately, it's a small project, but feels ugly. – Josh Cronkhite Feb 14 '19 at 19:37

0 Answers0