简体   繁体   English

C# 根据 x86 或 x64 切换依赖项

[英]C# Switch dependencies depending on x86 or x64

We´ve got a third party dll which is either x86 or x64, now we have to change the x64 dll with x86 dependent on the TargetPlatform.我们有一个 x86 或 x64 的第三方 dll,现在我们必须使用依赖于 TargetPlatform 的 x86 更改 x64 dll。 May someone tell how?有人可以告诉怎么做吗?

The first try was to override the dll with a post build script.第一次尝试是使用后期构建脚本覆盖 dll。

With Configuration Manager we could brand the build with x86, x64 and with the macro $(PlatformName) we could name the dll path relative to the platform (x64/x86)使用配置管理器,我们可以使用 x86、x64 标记构建,并使用宏 $(PlatformName) 我们可以命名相对于平台 (x64/x86) 的 dll 路径

Important to know is, that the macro has to be set in *.csproj file directly eg:重要的是,必须直接在 *.csproj 文件中设置宏,例如:

<Reference Include="DLLNAME, Version=4.9.0.0, Culture=neutral, PublicKeyToken=TOKEN, 
      processorArchitecture=$(PlatformName)">
      <HintPath>Lib\$(PlatformName)\DLLNAME.dll</HintPath>
    </Reference>

Also if there is a Plugin which should be compiled into the main-programm folder, the build path has to be changed in *.csproj file directly.另外,如果有需要编译到 main-programm 文件夹中的插件,则必须直接在 *.csproj 文件中更改构建路径。 Eg:例如:

 <OutputPath>..\..\bin\$(PlatformName)\Debug\Features\</OutputPath>

Thats because VS escapes the '$(' and ')'那是因为 VS 转义了'$('')'

EDIT: Too fast.编辑:太快了。 The <OutputPath> doesn´t understand macros. <OutputPath>不理解宏。 Therefore we had to change the outputpath for every Build-Configuration.因此,我们必须为每个构建配置更改输出路径。 Eg:例如:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>..\..\bin\x86\Debug\Features\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>..\..\bin\x86\Release\Features\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>

EDIT 2: For only x64 or x86 dependencies there is the Condition-Attribute which can seperate some cs-Files from x86 or x64 eg:编辑 2:仅对于 x64 或 x86 依赖项,有条件属性可以将一些 cs 文件与 x86 或 x64 分开,例如:

<Reference Condition="'$(Platform)'=='x64'" Include="STPadLibNet">
  <HintPath>Lib\x64\DLLNAME.dll</HintPath>
</Reference>

and for some Clases u can use it like:对于某些类,您可以像这样使用它:

<Compile Condition="'$(Platform)'=='x64'" Include="MyClass.cs" />

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

相关问题 根据 x64/x86 更改 C# DllImport 目标代码 - Change C# DllImport target code depending on x64/x86 C# 中的 x86/x64 CPUID - x86/x64 CPUID in C# C# 支持 x64 和 x86 - C# support both x64 and x86 创建具有 x64 和 x86 依赖项的安装程序 - Create installer with dependencies for x64 and x86 VisualStudio C#x64,为什么AddReference选项,.NET选项卡指向x86 DLL而不是x64? - VisualStudio C# x64, why AddReference option, .NET tab points to x86 DLL instead of x64? c#visual studio使用目标anycpu构建exe,但在调用进程平台(x86 / x64)上确定其平台(x86 / x64) - c# visual studio build exe with target anycpu but that determines its platform(x86/x64) on the calling process platform(x86/x64) 结合C#和C ++项目适用于x86和x64,但不适用于ARM - Combining a C# and C++ project works for x86 and x64 but not for ARM 用于C#应用程序的AnyCPU / x86 / x64及其C ++ / CLI依赖性 - AnyCPU/x86/x64 for C# application and it's C++/CLI dependency C# IO 不适用于 x64 或 x86 配置,仅适用于任何 CPU - C# IO doesn't work on x64 or on x86 configuration only on Any CPU 在VS2010中针对x86和x64处理器编译C#项目 - Compile a C# project in VS2010 both for x86 and x64 processors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM