为什么我会收到 Error CS0016 无法写入输出文件 的错误在 ASP.NET Core 7.0?

huangapple go评论77阅读模式
英文:

Why am I getting Error CS0016 Could not write to output file in ASP.NET Core 7.0?

问题

我遇到了这个错误:

> 错误 CS0016 无法写入输出文件 'C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\obj\Debug\net7.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Views_Shared__ValidationScriptsPartial_cshtml.g.cs' -- 无法找到路径的一部分 'C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\obj\Debug\net7.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Views_Shared__ValidationScriptsPartial_cshtml.g.cs'。 Mvc1 C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\CSS

Visual Studio 寻找的文件在这里:

C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\obj\Debug\net7.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Views_Shared__ValidationScriptsPartial_cshtml.g.cs

它不在那个位置,所以 Visual Studio 是正确的。

为什么我会收到 Error CS0016 无法写入输出文件 的错误在 ASP.NET Core 7.0?

我理解的是,像 Views_Shared__ValidationScriptsPartial_cshtml.g.cs 这样的生成文件应该来自路径 "Views > Shared > _ValidationScriptsPartial.cshtml" 中的一个文件,这个文件是存在的:

为什么我会收到 Error CS0016 无法写入输出文件 的错误在 ASP.NET Core 7.0?

我该如何修复这个错误?

英文:

I'm getting this error:

> Error CS0016 Could not write to output file 'C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\obj\Debug\net7.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Views_Shared__ValidationScriptsPartial_cshtml.g.cs' -- 'Could not find a part of the path 'C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\obj\Debug\net7.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Views_Shared__ValidationScriptsPartial_cshtml.g.cs'.' Mvc1 C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\CSS

The file Visual Studio is looking for is here:

C:\Users\jp2code\Documents\Visual Studio 2022\Projects\Core\Mvc1\Mvc1\obj\Debug\net7.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Views_Shared__ValidationScriptsPartial_cshtml.g.cs

It is not in that location, so Visual Studio is correct.

为什么我会收到 Error CS0016 无法写入输出文件 的错误在 ASP.NET Core 7.0?

My understanding is that a generated file like Views_Shared__ValidationScriptsPartial_cshtml.g.cs is supposed to come from a file in the path "Views > Shared > _ValidationScriptsPartial.cshtml", which DOES exist:

为什么我会收到 Error CS0016 无法写入输出文件 的错误在 ASP.NET Core 7.0?

How do I fix this error?

答案1

得分: 0

错误来自项目中的文件 _ValidationScriptsPartial.cshtml。此文件的内容只有2个脚本文件:

<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

我将该文件从项目中排除,项目可以正常重建。

我不明白这个错误。为什么Visual Studio会添加该文件,然后编译器抱怨找不到它呢?

英文:

The error was from the file _ValidationScriptsPartial.cshtml in the project. The contents of this file was just 2 script files:

<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

I excluded that one file from the project, and the project rebuilds fine.

I don't understand that error. Why would Visual Studio add that file, and then the compiler complain about not being able to find it?

huangapple
  • 本文由 发表于 2023年6月29日 05:19:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76576766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定