[英]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.