简体   繁体   English

由于 XmlSerialization (sgen.exe) 并且无法禁用,无法在 Visual Studio 2022 中构建项目

[英]Can't Build Project In Visual Studio 2022 Due To XmlSerialization (sgen.exe) And Can't Disable

I'm getting this error when I compile my project written in VS 2019 in dotnet which I've just migrated to dotnet core 6.0 and loaded into VS 2022.当我在 dotnet 中编译用 VS 2019 编写的项目时出现此错误,我刚刚迁移到 dotnet core 6.0 并加载到 VS 2022。

Error   MSB6003 The specified task executable "sgen.exe" could not be run. System.ComponentModel.Win32Exception (0x80004005): The filename or extension is too long

There appears to be a known issue with XmlSerialization failing due to long filenames.由于长文件名,XmlSerialization 似乎存在一个已知问题。 Fixes include turning off Generate Serialization assembly and the official MS fix of enabling long filenames since at least 2017 .修复包括关闭生成序列化程序集至少自 2017 年以来启用长文件名的官方 MS 修复。

Disabling XmlSerialization should be possible from the UI in VS 2019, and should be possible in the project file by adding:应该可以从 VS 2019 中的 UI 禁用 XmlSerialization,并且应该可以在项目文件中添加:

<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>

However, there is no option in VS 2022 to do this through the UI, and the config above seems to be ignored.但是,在 VS 2022 中没有选项可以通过 UI 执行此操作,并且上面的配置似乎被忽略了。 As such I can't see how to avoid the error in VS 2022. I've tried disabling it in the VS 2019 and loading in VS 2022, but that doesn't work.因此,我看不到如何避免 VS 2022 中的错误。我尝试在 VS 2019 中禁用它并在 VS 2022 中加载,但这不起作用。

Update: I also tried moving the solution to a dir on root with a 2 char name.更新:我还尝试将解决方案移动到具有 2 个字符名称的根目录。 No joy.没有喜悦。

Any ideas?有任何想法吗?

I just tried disabling in the project file again, and it worked this time.我只是尝试再次禁用项目文件,这次成功了。

<PropertyGroup>
   ...
   <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>

VS 2022 doesn't seem to have the UI option like VS 2019 so you seem to have to do this manually. VS 2022 似乎没有像 VS 2019 那样的 UI 选项,因此您似乎必须手动执行此操作。

I'm getting now a我现在得到一个

The command "copy "\\policy.xml" "" " exited with code 1 error

but that's a different problem...但这是一个不同的问题......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM