我在dot net项目中测试了C#8。特别是对可空引用类型的支持。在编译项目时,我收到了很多关于生成的Razor页面输出的警告。
2>obj\Debug\netcoreapp2.1\Razor\Pages\_ViewStart.g.cshtml.cs(23,18,23,34): warning CS8618: Non-nullable property 'ModelExpressionProvider' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\Account\_ViewImports.g.cshtml.cs(28,18,28,44): warning CS8618: Non-nullable property 'ModelExpressionProvider' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\_ViewStart.g.cshtml.cs(23,18,23,34): warning CS8618: Non-nullable property 'Url' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\Account\_ViewImports.g.cshtml.cs(28,18,28,44): warning CS8618: Non-nullable property 'Url' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\_ViewStart.g.cshtml.cs(23,18,23,34): warning CS8618: Non-nullable property 'Component' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\Account\_ViewImports.g.cshtml.cs(28,18,28,44): warning CS8618: Non-nullable property 'Component' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\_ViewStart.g.cshtml.cs(23,18,23,34): warning CS8618: Non-nullable property 'Json' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\Account\_ViewImports.g.cshtml.cs(28,18,28,44): warning CS8618: Non-nullable property 'Json' is uninitialized.
2>obj\Debug\netcoreapp2.1\Razor\Pages\_ViewStart.g.cshtml.cs(23,18,23,34): warning CS8618: Non-nullable property 'Html' is uninitialized.
由于生成的输出不会禁用可空性警告,因此很多生成的代码会触发它们并产生警告。
如果我可以在构建禁用警告的项目时将自己的pragma注入Razor页面,那将会很棒。可能使用自定义MSBuild目标或类似目标。这可能吗?