Build project targeting for both x86 and x64 platform

心已入冬 提交于 2021-02-10 05:42:27

问题


In my solution, there is a class library which is an excel add-in. When I build the solution or that project, I want this project will be built firstly targeting for x86 with outputing a file named xxx.dll, and then targeting for x64 with outputing a file named xxx_x64.dll.

How should I do for this, or how could I edit the csproj file? Thanks.


回答1:


How should I do for this, or how could I edit the csproj file?

The name of assembly xxx.dll is defined by the property AssemblyName in the project file, if you want to change the default output assembly named with platform, you can simple change the value of this property with following code in the project file .csproj:

<AssemblyName>TestWithDllWithPlatform_$(Platform)</AssemblyName>

But with this setting, you will get the output assembly named xxx_x86.dll when you targeting for x86.

If you still want targeting for x86 with outputing a file named xxx.dll rather than xxx_x86.dll, you can try to rename the dll file with post-build event when you targeting for x64:

if $(Platform) == x64 (copy /y "$(TargetPath)" "$(ProjectDir)$(OutDir)$(TargetName)_$(Platform).dll")

In this case, when you targeting x64, outputing assembly named would be xxx_x64.dll:

Besides, if you do not want keep the original xxx_.dll, you can delete it with below command in the post-build:

if $(Platform) == x64 (del "$(TargetPath)")

Hope this helps.




回答2:


Finally, I have solved this problem by using Shared Project in Visual Studio. What I want is two Excel Addin assemblies will be generated by building the solution, one is targeting to x86 platform or AnyCPU, the other is targeting to x64 platform.

Here is my projects snapshot:

All the code files(*.cs) and resources(images or xml files) are moved into the Shared project, and both the other 2 projects have a reference to it.

As to the other 2 projects, there are some differences between them, e.g. Assembly Name and Target Platform. One is XXX.dll and targeting AnyCPU, the other is XXX_64.dll and targeting x64.

When building the solution, each of the 2 projects will issue the corresponding assembly.



来源:https://stackoverflow.com/questions/47585539/build-project-targeting-for-both-x86-and-x64-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!