WPInfo
WPInfo

Reputation: 1076

Build project targeting for both x86 and x64 platform

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.

Upvotes: 3

Views: 1895

Answers (2)

WPInfo
WPInfo

Reputation: 1076

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:

enter image description here

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.

Upvotes: 0

Leo Liu
Leo Liu

Reputation: 76760

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:

enter image description here

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.

Upvotes: 2

Related Questions