本文介绍了在相同的解决方案/项目的Visual Studio针对32位和64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何建立我的Visual Studio有点进退两难建立多定位。

I have a little dilemma on how to set up my visual studio builds for multi-targeting.

背景:C#.NET 2.0版与P /调用到第三方32位DLL的,SQL紧凑版本3.5 SP1,与安装项目。目前,该平台的目标设定为86,因此它可以在Windows 64上运行。

Background: c# .NET v2.0 with p/invoking into 3rd party 32 bit DLL's, SQL compact v3.5 SP1, with a Setup project.Right now, the platform target is set to x86 so it can be run on Windows x64.

该第三方公司刚刚发布了64位版本的DLL的,我想建立一个专用的64位程序。

The 3rd party company has just released 64 bit versions of their DLL's and I want to build a dedicated 64bit program.

这引起了我还没有得到答案,但一些问题。我想有完全相同的code基地。我必须建立与参考要么32位集DLL的或64位DLL的。(无论第三方和SQL Server Compact)

This raises some questions which I haven't got the answers to yet.I want to have the exact same code base.I must build with references to either the 32bit set of DLL's or 64bit DLL's.(Both 3rd party and SQL Server Compact)

可以这样用配置2个新集(Debug64和Release64)?解决

Can this be solved with 2 new sets of configurations (Debug64 and Release64) ?

我必须建立2个独立的安装项目(标准的Visual Studio项目,没有维克斯或任何其他实用程序),或者可以这样在同一个的.msi内解决了吗?

Must I create 2 separate setup projects(std. visual studio projects, no Wix or any other utility), or can this be solved within the same .msi?

任何想法和/或建议将受到欢迎。

Any ideas and/or recommendations would be welcomed.

推荐答案

是的,你可以针对x86和x64的,在同一项目同一code碱基。我发现需要特别注意的项目有:一般情况下,如果您在VS.NET的解决方案配置(虽然P / Invoke来完全非托管的DLL将最有可能需要一些条件code)的事情会只是工作:

Yes, you can target both x86 and x64 with the same code base in the same project. In general, things will Just Work if you create the right solution configurations in VS.NET (although P/Invoke to entirely unmanaged DLLs will most likely require some conditional code): the items that I found to require special attention are:

  • 具有相同的名字,但自己的特定位数引用外部托管程序集(这也适用于COM互操作集)
  • MSI软件包(正如已经指出,将需要针对x86或x64)
  • 在MSI包中的任何自定义.NET安装程序类为基础的行动

完全在VS.NET中集引用问题不能得到解决,因为这将只允许您用一个给定的名称添加一个参考项目的一次。要解决此问题,手动编辑项目文件(在VS中,用鼠标右键单击在Solution Explorer中的项目文件,选择卸载项目,然后再次单击右键,然后选择编辑)。增加提及,比如说,组件的x86版本后,你的项目文件将包含类似:

The assembly reference issue can't be solved entirely within VS.NET, as it will only allow you to add a reference with a given name to a project once. To work around this, edit your project file manually (in VS, right-click your project file in the Solution Explorer, select Unload Project, then right-click again and select Edit). After adding a reference to, say, the x86 version of an assembly, your project file will contain something like:

<Reference Include="Filename, ..., processorArchitecture=x86">
  <HintPath>C:\path\to\x86\DLL</HintPath>
</Reference>

总结了参考标记的ItemGroup标签中表明它适用于解决方案配置,如:

Wrap that Reference tag inside an ItemGroup tag indicating the solution configuration it applies to, e.g:

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
   <Reference ...>....</Reference>
</ItemGroup>

然后,复制和粘贴整个ItemGroup标签,并编辑它包含您的64位DLL的详细信息,如:

Then, copy and paste the entire ItemGroup tag, and edit it to contain the details of your 64-bit DLL, e.g.:

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
  <Reference Include="Filename, ..., processorArchitecture=AMD64">
     <HintPath>C:\path\to\x64\DLL</HintPath>
   </Reference>
</ItemGroup>

在重装项目在VS.NET,大会引用对话框会有点受这些变化感到困惑,你可能会遇到有关与错误的目标处理器集会一些警告,但所有的构建会工作得很好。

After reloading your project in VS.NET, the Assembly Reference dialog will be a bit confused by these changes, and you may encounter some warnings about assemblies with the wrong target processor, but all your builds will work just fine.

解决MSI问题是旁边,可惜这个的要求non-VS.NET工具:我preFER Caphyon的的用于这一目的,因为它拉了涉及基本的技巧(创建一个共同的微星,以及32位和64位的具体MSI的,并使用一个.exe安装程序启动提取正确的版本,并做必要的修正在运行时)非常,非常好。

Solving the MSI issue is up next, and unfortunately this will require a non-VS.NET tool: I prefer Caphyon's Advanced Installer for that purpose, as it pulls off the basic trick involved (create a common MSI, as well as 32-bit and 64-bit specific MSIs, and use an .EXE setup launcher to extract the right version and do the required fixups at runtime) very, very well.

您可以使用其他工具或的Windows Installer XML(WiX的)工具可能达到同样的效果,但高级安装程序使事情变得如此简单的(并且是相当实惠的那个),我从来没有真正看的替代品。

You can probably achieve the same results using other tools or the Windows Installer XML (WiX) toolset, but Advanced Installer makes things so easy (and is quite affordable at that) that I've never really looked at alternatives.

有一件事你可以仍然需要维克斯因为虽然,即使是使用高级安装的时候,是你的.NET安装程序类的自定义操作。虽然是微不足道的指定特定的行动,只能运行在特定的平台上(使用VersionNT64和NOT VersionNT64执行情况,分别),内置将使用32位的框架来执行AI的自定义操作,即使在64位机器

One thing you may still require WiX for though, even when using Advanced Installer, is for your .NET Installer Class custom actions. Although it's trivial to specify certain actions that should only run on certain platforms (using the VersionNT64 and NOT VersionNT64 execution conditions, respectively), the built-in AI custom actions will be executed using the 32-bit Framework, even on 64-bit machines.

这可能是固定在将来的版本,但现在(或使用不同的工具来创建你的MSI有同样的问题时),您可以使用WiX的3.0的托管自定义操作支持创建操作DLL与将使用相应的框架来执行适当的位数。

This may be fixed in a future release, but for now (or when using a different tool to create your MSIs that has the same issue), you can use WiX 3.0's managed custom action support to create action DLLs with the proper bitness that will be executed using the corresponding Framework.

编辑:为8.1.2版本,高级安装正确支持64位的自定义操作。因为我原来的答案,它的价格已经增加了不少,可惜的是,尽管它非常良好的价值相比,InstallShield和仍然是它的同类......

as of version 8.1.2, Advanced Installer correctly supports 64-bit custom actions. Since my original answer, its price has increased quite a bit, unfortunately, even though it's still extremely good value when compared to InstallShield and its ilk...

编辑:如果你的DLL被注册在GAC中,您还可以使用标准的参考标签这种方式(SQLite作为一个例子):

If your DLLs are registered in the GAC, you can also use the standard reference tags this way (SQLite as an example):

<ItemGroup Condition="'$(Platform)' == 'x86'">
    <Reference Include="System.Data.SQLite, Version=1.0.80.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86" />
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64'">
    <Reference Include="System.Data.SQLite, Version=1.0.80.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64" />
</ItemGroup>

病情也下降到所有类型的建立,释放或调试,只是指定的处理器架构。

The condition is also reduced down to all build types, release or debug, and just specifies the processor architecture.

这篇关于在相同的解决方案/项目的Visual Studio针对32位和64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:47