首页 > 其他分享 >.net core 添加dll的路径引用

.net core 添加dll的路径引用

时间:2023-01-19 19:12:49浏览次数:49  
标签:core ReferencePath csproj dll 构建 build dotnet net

原文网址:https://www.codenong.com/50057777/

.NET Core - build project specifying ReferencePath

我有一个.csproj用于.NetCore平台,具有经典参考。 我在开发环境中使用hintpath属性。 但是我应该在CI环境上构建csproj,将引用程序集放置在其他目录中。
在经典的net4上,我已将/p:ReferencePath参数用于MSBuild工具。
但是" dotnet构建"没有类似的论点。
作为备用,我找到了" dotnet msbuild"命令,但是此工具忽略了/p:ReferencePath=xxx参数并显示给我

warning MSB3245: Could not resolve this reference. Could not locate the assembly"AssemblyName". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

请指导我,我能检查什么,dotnet-build / dotnet-msbuild工具在哪里搜索引用的程序集以及如何指定该目录?


Microsoft.NET.Sdk.props解决了此问题:AssemblySearchPaths没有ReferencePath。
通过添加到csproj进行修复:

1
2
3
4
5
6
<PropertyGroup>
    <AssemblySearchPaths>
        $(AssemblySearchPaths);
        $(ReferencePath);
    </AssemblySearchPaths>
</PropertyGroup>

  • 您仍然可以使用MSBUILD在解决方案中构建.net CORE / Standard项目。
  • 我向Microsoft报告的这似乎是一个错误(该错误与核心/标准无关,而是新的项目文件格式),referencePath被新的项目文件格式忽略。
  • 将add /t:restore与构建目标一起提供给msbuild命令,这样它将同时还原和构建。
  • 针对CI / Build服务器情况的解决方法是创建一个特殊的解决方案配置,并将类似以下内容的内容添加到您的项目文件中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<Choose>  
  <When Condition="'$(Configuration)|$(Platform)'=='YourSpecialConfiguration|x64'"><!-- attention here -->
    <ItemGroup>
      <Reference Include="your.dllname">
        <HintPath>yourSpecialPath\your.dllname.dll</HintPath><!-- attention here -->
        <Private>true</Private>
      </Reference>
      <!-- more references here -->
  </When>
  <Otherwise>
    <ItemGroup>
      <Reference Include="your.dllname">
        <HintPath>yourRegularPath\your.dllname.dll</HintPath><!-- attention here -->
        <Private>true</Private>
      </Reference>
      <!-- AND more references here -->
  </Otherwise>
</Choose>

这将允许您仅更改CI / Build中的配置名称即可完成此工作。

 

 

 


But the"dotnet build" has no similar argument.

你为什么这么说?

dotnet cli仍支持-p而不是/p的"属性注入"。链接(搜索" -p")

对于您的问题,build命令将类似于以下命令:

dotnet build -p:ReferencePath=xxx

 

 

标签:core,ReferencePath,csproj,dll,构建,build,dotnet,net
From: https://www.cnblogs.com/bruce1992/p/17061983.html

相关文章

  • 完美解决dotnet-install.sh下载出错
    问题现象Linux正常通过dotnet-install.sh安装dotnet(本篇以安装dotnet-runtime为例)时,会显示以下信息:dotnet-install:Notethattheintendeduseofthisscriptisfor......
  • 新版本S1730系列交换机配置telnet
    当前新版本交换机为了安全新增了相关安全特性,对应的配置telnet的步骤参考如下第一步:开启telnet服务<Huawei>system-view [Huawei]telnet server enable  第二......
  • C#/VB.NET 在Excel中添加水印
    在工作中,为了防止文件被随意复制和传播,通常我们会选择在文档中添加水印来对文件进行有效保护。文字水印是比较常见的一种保护手段,它可以有效防止文件被任意复制和随意打印......
  • 工控小工具 snmp 、opc ua 、modbus 、tcp、bacnet 开发环境Net6.0
    下载地址https://files.cnblogs.com/files/blogs/745639/net6.0-windows.rar?t=1674114312             ......
  • 【Azure 存储服务】.NET7.0 示例代码之上传大文件到Azure Storage Blob
    问题描述在使用Azure的存储服务时候,如果上传的文件大于了100MB,1GB的情况下,如何上传呢? 问题解答使用Azure存储服务时,如果要上传文件到AzureBlob,有很多种工具可以实现......
  • DBNet源码详解
    参考项目:https://github.com/WenmuZhou/DBNet.pytorch标签制作制作thresholdmap标签make_border_map.py程序入口if__name__=='__main__'if__name__=='__main......
  • 如何通过C#/VB.NET将格式应用于 Word 中的字符
    字符格式设置是指用户对字符的屏幕显示和打印输出形式的设定。Word文档中的字符格式有:字体、字号、字体颜色、高亮颜色、边框、下划线、斜体、阴影字、着重号等等。带格式......
  • inet_pton和inet_ntop函数
    Linux下这2个IP地址转换函数,可以在将IP地址在“点分十进制”和“整数”之间转换而且,inet_pton和inet_ntop这2个函数能够处理ipv4和ipv6。算是比较新的函数了。ine......
  • IIS 部署.NetCore
    1.安装.netcore运行时​​https://dotnet.microsoft.com/download/dotnet/3.1/runtime​​Windows安装,选择desktopapps2.安装捆绑应用选择好版本后,点击去,找到Core运行时......
  • 使用PInvoke.net
    C#和C++的交互如果自己写代码,一方面繁琐,另一方面容易出错,再者就是代码不太规范。最近看了一下PInvoke.net的东西,可以直接使用官方写好的。下面是使用Pinvoke.net打开设备......