简体   繁体   English

强制Visual Studio重建嵌入式资源

[英]Force Visual Studio Rebuild on Embedded Resource Changed

We have a SQL file that's an embedded resource in our solution. 我们有一个SQL文件,它是我们解决方案中的嵌入式资源。 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. 当sql文件发生更改并且我们单击debug时,如果没有更改实际的C#代码,则解决方案不会使用嵌入式资源重建项目。

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. 我已经遇到过其他解决方案的这个问题,只要我记得,而且我个人知道要做Build Solution以确保它已经构建......但这已成为一些不记得的新开发人员的问题当他们对SQL文件的更改没有在调试时反映时,这样做并感到困惑...所以我想知道是否有人知道一个简单的修复。

The easiest fix is to "rebuild" instead of "build". 最简单的解决方法是“重建”而不是“构建”。 Other people will "clean" and then "build" to be 100% sure. 其他人将“清理”,然后“建立”100%肯定。

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. 除非输出DLL被截断,否则嵌入式资源不会在调试DLL中更新,只能通过重建和清理来保证。

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: 我的问题是使用字符串资源文件,我在VS2016中如何修复如下:

  1. Close .resx and .Designer.cs if they are open in the IDE 如果它们在IDE中打开,请关闭.resx和.Designer.cs
  2. Delete .Designer.cs class (right-click, delete in solution explorer) 删除.Designer.cs类(右键单击,在解决方案资源管理器中删除)
  3. Double click .resx file in solution explorer to open 双击解决方案资源管理器中的.resx文件以打开
  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 将“无法生成代码”中的“访问修饰符”更改为“公共”,然后保存=> .Designer.cs代码应该更新

I ran into the same issue with VS2017. 我遇到了与VS2017相同的问题。

This is what worked for me: 这对我有用:

  1. Open the .resx file. 打开.resx文件。 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 确保您在资源编辑器中 ,不要使用XML编辑器,因为有时进行的更改不会触发Designer.cs的生成
  2. Make sure Designer.cs is not open. 确保Designer.cs未打开。
  3. Do a small change, save 做一个小改动,保存
  4. Undo the change, save 撤消更改,保存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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