简体   繁体   中英

Force Visual Studio Rebuild on Embedded Resource Changed

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM