英文:
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 是正确的。
我理解的是,像 Views_Shared__ValidationScriptsPartial_cshtml.g.cs
这样的生成文件应该来自路径 "Views > Shared > _ValidationScriptsPartial.cshtml" 中的一个文件,这个文件是存在的:
我该如何修复这个错误?
英文:
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.
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:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论