zoukankan      html  css  js  c++  java
  • C#工程中 使用targets和props实例

    描述:

      需要使用的C++类库区分x64和x86版本,在C#工程编译时根据编译选项自动选择dll库版本并复制到输出路径

    解决:

      1.准备dll库编译好的两个版本;

      2.在C#项目中引用随编一个(一般x64,x86引用文件都一致);  

      3.卸载该项目后,修改C#工程文件(*.csproj)

        3.1 找到自动生成的引用节点

    <Reference Include="CefSharp">
    <HintPath>DLLsx64CefSharp.dll</HintPath>
    </Reference>
        3.2 添加引用条件   Condition=" '$(Platform)' == 'x64'"
    <Reference Include="CefSharp" Condition=" '$(Platform)' == 'x64'">
    <HintPath>DLLsx64CefSharp.dll</HintPath>
    </Reference>
        3.3 同理X86版本进行修改
    <Reference Include="CefSharp" Condition=" '$(Platform)' == 'x86'">
    <HintPath>DLLsx86CefSharp.dll</HintPath>
    </Reference>
      4.保存后重新加载该工程即可;
     

    Note:

      1.貌似也可以动态指定路径:

    <Reference Include="CefSharp.Core">
      <HintPath>DLLs$(Platform)CefSharp.Core.dll</HintPath>
    </Reference>
      2.添加自动复制脚本
      2.1 添加targets文件,在该文件中定义所含目标文件(文件内容):
    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup Condition="Exists('$(MSBuildThisFileDirectory)DLLsx86')">
        <CefDlls32 Include="$(MSBuildThisFileDirectory)DLLsx86*.*" />
      </ItemGroup>
      
      <ItemGroup Condition="Exists('$(MSBuildThisFileDirectory)DLLsx64')">
        <CefDlls64 Include="$(MSBuildThisFileDirectory)DLLsx64*.*" />
      </ItemGroup>
    </Project>

      2.2 添加props文件,并在文件中写入复制信息以及路径:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    
      <Target Name="CefSharpCopyDlls86" BeforeTargets="AfterBuild" Condition="'$(Platform)' == 'x86'">
        <Message Importance="high" Text="Copying cef.dlls x86 binaries" />
        <Copy SourceFiles="@(CefDlls32)" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />  
        </Target>  
    
      <Target Name="CefSharpCopyDlls64" BeforeTargets="AfterBuild" Condition="'$(Platform)' == 'x64'">
        <Message Importance="high" Text="Copying cef.dlls x64 binaries" />
        <Copy SourceFiles="@(CefDlls64)" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
      </Target>  
      
    </Project>

       2.3 在项目文件中导入两个文件,ok;

    <Import Project="DLLsCefDlls.Native.props" Condition="Exists('DLLsCefDlls.Native.props')" />
    <Import Project="Dllscef.dlls.targets" Condition="Exists('Dllscef.dlls.targets')" />
      
      2.4 验证成功,编译输出信息;
  • 相关阅读:
    ACM: HDU 2544 最短路-Dijkstra算法
    ACM: HDU 1874 畅通工程续-Dijkstra算法
    ACM: SGU 101 Domino- 欧拉回路-并查集
    ACM: HDU 1285 确定比赛名次
    ACM: hdu 2647 Reward -拓扑排序
    ACM: hdu 1811 Rank of Tetris
    ACM: poj 1094 Sorting It All Out
    ACM: hihicoder #1174 : 拓扑排序·一 STL- queue
    ACM: CodeForces 140A New Year Table-数学几何
    POJ 3122 Pie 二分枚举
  • 原文地址:https://www.cnblogs.com/forevertime/p/7458899.html
Copyright © 2011-2022 走看看