自动生成的文件(Silverlight *.gics 文件)不'当“将警告视为错误”打开时,似乎被忽略

发布于 2024-09-27 15:25:31 字数 567 浏览 4 评论 0原文

我正在努力成为一名优秀的开发人员,并打开将警告视为错误的功能(就像我过去一直所做的那样)。最大的区别是,这次我使用的是 Silverlight 4,它会生成大量代码。所有代码的开头都是这样的:

#pragma checksum <some stuff>
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//---------

但是,将警告视为错误并不是忽略它。我的印象是,包含这样的标头会导致文件被忽略。显然,我错了。有人有(干净的)建议吗?

I'm trying to be a good dev and turn on treat warnings as errors (as I have always done in the past). The biggest difference is that this time, I'm using Silverlight 4 which generates a ton of code. All of the code starts something like this:

#pragma checksum <some stuff>
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//---------

However, the treat warnings as errors is not ignoring it. I was under the impression that including such a header would cause the file to be ignored. Apparently, I'm wrong. Does anyone have a (clean) suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傲性难收 2024-10-04 15:25:31

当我从解决方案目录中删除所有 BIN 和 OBJ 文件夹(以制作较小的源文件备份文件)时,我遇到了同样的问题。

我将项目属性中的目标 Silverlight 版本从 SL4 更改为 SL3,然后又切换回 SL4。这对我有用。

I had the same issue when I deleted all the BIN and OBJ folders from solution directory (to make a smaller backup file of the source files).

I changed the Target Silverlight Version in Project Properties from SL4 to SL3 and then switched backed to SL4. It worked for me.

星星的轨迹 2024-10-04 15:25:31

我花了很长时间才找到一个可接受的解决方法 - 但这比更改 Target Silverlight 版本要好得多。

解决方法,如 MSDN,正在构建之前删除所有 *.gics 文件。

下面是执行此操作的 F# 脚本(可在 MSDN 解决方法部分中找到):

open System
open System.IO

let deleteUserFile file =
    printfn "%s" file
    File.Delete(file)

Directory.GetFiles( @".", "*g.i.cs", SearchOption.AllDirectories )
|> Array.iter deleteUserFile

这解决了错误。下次它出现时,我所要做的就是执行一个文件,该文件将清理项目文件夹中的所有 gics 文件。

编辑:我升级到 Silverlight 5,但再次出现此问题。这里列出的建议都不起作用(切换到 SL4 然后返回 SL5 或仅删除 gics 文件) - 但是删除 Silverlight 项目的 BIN 和 OBJ 文件夹可以解决问题。

It took me a long while to find out an acceptable workaround - but it's much better than changing the Target Silverlight version.

The workaround, as mentioned at MSDN, is deleting all your *.g.i.cs files prior to the build.

Here is an F# script to do this (as found in the MSDN workarounds section):

open System
open System.IO

let deleteUserFile file =
    printfn "%s" file
    File.Delete(file)

Directory.GetFiles( @".", "*g.i.cs", SearchOption.AllDirectories )
|> Array.iter deleteUserFile

This solved the error. Next time it shows up, all I have to is execute a file that'll clean all the g.i.cs files in my projects folder.

Edit: I upgraded to Silverlight 5 and have this issue happen again. None of the suggestions listed here worked (switching to SL4 then back to SL5 or only deleting the g.i.cs files)- however deleting the BIN and OBJ folders of the Silverlight project did the trick.

执笏见 2024-10-04 15:25:31

好吧,事实证明,至少在我的情况下,来自生成文件的唯一警告是由于我创建了我的页面继承的自定义基本 Silverlight 页面而产生的。您可以通过从项目中删除 XAML 文件并将 xaml.cs 代码隐藏文件重新添加回项目来修复此类情况导致的编译器警告问题。这会导致 LayoutRoot 未定义,并且代码生成器不会为此基类生成 InitializeComponent 方法。希望这对其他人也有帮助!

Okay, so it turns out that, at least in my case, the only warnings coming from the generated files were resulting from my creation of a custom base Silverlight page that my pages inherited from. You can fix the issue of compiler warnings resulting from this type of scenario by removing the XAML file from the project and re-adding the xaml.cs code-behind file back to the project. This causes the LayoutRoot to not be defined, and the code generator to not generate the InitializeComponent method for this base class. Hopefully this will help someone else, too!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文