我目前正在研究将我们的工具集从VS2013、15和17迁移到VS2022,以便简化和减少构建解决方案所需的软件数量。VS2022有我们需要的所有部分,但是我很难通过VS本身来获得实际的解决方案。
如果我在path C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe
上使用附带的32位msbuild版本,那么这个解决方案就会构建得很好。然而,C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\amd64\MSBuild.exe
版本(我猜VS22使用了吗?)无法生成与通过VS22生成相同的错误。
需要注意的是,我们的解决方案/项目主要基于.net framework 2.0
(不幸的是),并且设置为x86
平台。
我一直循环返回到各种第一和第三方dll的错误SGEN : error : An attempt was made to load an assembly with an incorrect format
。我一直在反复尝试以下的组合:
在configurations
AnyCPU
之间更改项目的Generate serialization assembly
’,我在某个地方看到,人们已经成功地解决了错误,从4.0
(我们当前的设置)到Current
和其他版本F 218
我正在有效地寻找一种方法来强制VS2022使用32位的msbuild (如果可能的话),因为它构建了整个解决方案,根本不做任何更改。
我还注意到VS输出窗口中的以下内容:
Task attempted to find "sgen.exe" using the SdkToolsPath value "". Make sure the SdkToolsPath is set to the correct value and the tool exists in the correct processor specific location below it. (TaskId:109)
4> C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\sgen.exe
将SdkToolsPath
设置为32位版本可以解决我的问题吗?实际上我还没能找到在哪里试一试。
谢谢!
发布于 2022-02-01 09:39:52
对我们起作用的是手动在SGenToolPath
文件中重写.csproj项目属性。
添加以下内容:
<Target Name="SGENBeforeBuild" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<!-- workaround for VS2022 x64 building serialization assemblies for x86 targets
, see https://stackoverflow.com/questions/70770918/forcing-vs2022-to-use-32-bit-version-of-msbuild -->
<SGenToolPath>$(TargetFrameworkSDKToolsDirectory)</SGenToolPath>
</PropertyGroup>
</Target>
有趣的是,我们不得不在一些以x86为目标的项目中使用这个解决方案,而不是所有这些项目。
实际上,在许多Visual构建工具步骤中,您可能会遇到类似的问题。下面是一个MSDN页面,其中列出了大多数Visual (2022)构建工具的项目属性:
https://stackoverflow.com/questions/70770918
复制相似问题