Visual Studio duplicating resource .cs file

有些话、适合烂在心里 提交于 2019-12-03 08:16:58

问题


Visual Studio has begun exhibiting a rather irritating quirk. When I edit a resource file (using either the designer view or editing the XML directly), it creates a duplicate resource Designer.cs file, which causes the project to be unable to build.

Example: Let's say my resource file is called ProjectSQL.resx. If you expand ProjectSQL.resx in the Solution Explorer, it shows ProjectSQL.Designer.cs. When I make an edit to one of the queries defined in ProjectSQL.resx, it saves fine, but creates another file called ProjectSQL1.Designer.cs.

In that example, there's now two class files with the same class name, causing the build failure.

Has anyone had this problem before? How did you fix it? I've tried closing the solution and reopening, as well as restarting Visual Studio. Using VS 2010 Premium on Windows 7 Ultimate for those interested.


回答1:


In case this happens to anyone else and you find yourself here, Hans' comment above pointed me toward the project file. I had to close the solution, find the LastGenOutput tag in the project XML file, and change the name of the resource output back to ProjectSQL from ProjectSQL1.

I still have no idea how this happened. But at least it's fixed now.




回答2:


Replace in .csproj file the code like below:

<EmbeddedResource Include="Resources\ProjectSQL.resx">
   <Generator>ResXFileCodeGenerator</Generator>
   <LastGenOutput>ProjectSQL1.Designer.cs</LastGenOutput>
</EmbeddedResource>

With code like below:-

<EmbeddedResource Include="Resources\ProjectSQL.resx">    
   <Generator>ResXFileCodeGenerator</Generator>
   <LastGenOutput>ProjectSQL.Designer.cs</LastGenOutput>
</EmbeddedResource>

Source: http://www.codeproject.com/Questions/227676/Resource-file-regenerating




回答3:


Clear the "Custom Tool" entry. appropriate rpt file it's located right click on rpt file --> properties ---> custom tool ---> clear



来源:https://stackoverflow.com/questions/23503130/visual-studio-duplicating-resource-cs-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!