.net 试图编译配置文件

.net trying to compile config file

我以前从未见过 Visual Studio 尝试编译 web.config 文件。但是我几乎在文件的每一行都遇到了编译错误。

第一行包括

<?xml version="1.0"?>    

我得到了 7 个错误。

Severity    Code    Description Project File    Line    Suppression State
Error   CS1022  Type or namespace definition, or end-of-file expected   Portal  {Path}\Views\Web.config 1   Active
Error   CS1031  Type expected   Portal  {Path}\Views\Web.config 1   Active
Error   CS1002  ; expected  Portal  {Path}\Views\Web.config 1   Active
Error   CS0116  A namespace cannot directly contain members such as fields or methods   Portal  {Path}\Views\Web.config 1   Active
Error   CS1022  Type or namespace definition, or end-of-file expected   Portal  {Path}\Views\Web.config 1   Active
Error   CS1031  Type expected   Portal  {Path}\Views\Web.config 1   Active
Error   CS1022  Type or namespace definition, or end-of-file expected   Portal  {Path}\Views\Web.config 1   Active

为什么要编译这个文件,我该如何告诉它不要编译?

从项目中删除文件并重新添加它解决了问题。 比较前后,csproj 将文件列为编译而不是内容。

<Content Include="{Path}\Web.config" />