18

We have a SQL file that's an embedded resource in our solution. When the sql file changes, and we click debug, the solution doesn't rebuild the project with the embedded resource if no actual C# code has changed.

I've had this issue with other solutions as long as I can remember, and I personally know to do Build Solution to make sure it gets built...but this has become an issue for a number of new developers who can't remember to do this and get confused when their changes to the SQL file aren't reflected at debug time...so I was wondering if anyone knows an easy fix.

Jeff
  • 35,755
  • 15
  • 108
  • 220
  • What are you embedding in regards to the SQL resource..? perhaps this could be the issue.. can you give a more detailed explanation..? – MethodMan Jan 03 '12 at 17:07
  • is having `SQL file` like embeded resource is a mandatory option ?. I mean, if it would be a separate file, there is a workarround, to copy that file on successfull build with `xcopy`, by defining it inside `Project properties`. – Tigran Jan 03 '12 at 17:08
  • The embedded resource is necessary. It's packaged into a custom action assembly used by an installer to run migration scripts. The same assembly is used in Debug mode of the app to make sure the DB they're running against is up to date. – Jeff Jan 03 '12 at 18:02
  • 1
    @Jeff Six year later did you find a solution to your problem? except rebuild or clean of course – Bobby Tables Apr 17 '18 at 15:51
  • Related: in [this answer](https://stackoverflow.com/a/16428739/1497596), using Solution Explorer to rebuild/recreate the `.Designer.cs` file from the `.resx` file. – DavidRR Nov 05 '18 at 16:01
  • 2
    Super annoying that this doesn't have an easy/obvious fix in 2020 (VS 2019). I've lost track of the number of times I've struggled to understand why a change I made to an embedded resource and not have it show in the build. Always having to remember to do Rebuild stinks. – tig Jan 02 '20 at 21:18

3 Answers3

4

Unfortunately, a clean and rebuild does not seem to always work for Resource files. My issue was with a string resource file, and how I fixed was as follows in VS2016:

  1. Close .resx and .Designer.cs if they are open in the IDE
  2. Delete .Designer.cs class (right-click, delete in solution explorer)
  3. Double click .resx file in solution explorer to open
  4. If required, change 'Access Modifier' from 'Public' to 'No Code Generation', and save
  5. Change 'Access Modifier' from 'No Code Generation' to 'Public', and save => the .Designer.cs code should then update
david.barkhuizen
  • 5,239
  • 4
  • 36
  • 38
4

The easiest fix is to "rebuild" instead of "build". Other people will "clean" and then "build" to be 100% sure.

Embedded Resources are not updated in the debugging DLLs unless the output DLL is truncated, which can only be guaranteed to occur with rebuild and clean.

Squirrelsama
  • 5,480
  • 4
  • 28
  • 38
  • 2
    Rebuild is defined to clean then build; there's no extra safety in doing an explicit clean (perhaps other than being sure you pressed the right button/key-combo) – Eamon Nerbonne Jul 12 '12 at 10:40
  • Unfortunately the "Rebuild" option works for manual usages, but not for builds automatically triggered by tools like Resharper Unit Test runner. – AFract Apr 20 '21 at 15:21
0

I ran into the same issue with VS2017.

This is what worked for me:

  1. Open the .resx file. Make sure you are in the Resource editor, do not use an XML editor since sometimes changes done there will not trigger the generation of Designer.cs
  2. Make sure Designer.cs is not open.
  3. Do a small change, save
  4. Undo the change, save
Chepech
  • 5,258
  • 4
  • 47
  • 70