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 验证成功,编译输出信息;
  • 相关阅读:
    git 查看远程分支、本地分支、删除本地分支
    iOS edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性详解
    【iOS开发】UIWebView与JavaScript(JS) 回调交互
    iOS打印Debug日志的方式
    iOS项目上传到AppStore步骤流程
    IOS开发之实现App消息推送(最新)
    DKNightVersion 的实现 --- 如何为 iOS 应用添加夜间模式
    用Session实现验证码
    HTTP中Get与Post、ViewState 原理
    ASP.NET获取服务器文件的物理路径
  • 原文地址:https://www.cnblogs.com/forevertime/p/7458899.html
Copyright © 2011-2022 走看看