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 验证成功,编译输出信息;
  • 相关阅读:
    python之----------字符编码具体原理
    css部分复习整理
    秘钥登录服务器执行shell脚本
    idea配置github
    InteliJ IDEA 简单使用:配置项目所需jdk
    IntelliJ IDEA 中安装junit插件
    IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set
    idea如何编译maven项目
    idea项目左边栏只能看到文件看不到项目结构
    idea如何导入一个maven项目
  • 原文地址:https://www.cnblogs.com/forevertime/p/7458899.html
Copyright © 2011-2022 走看看