.net core 添加dll的路径引用
原文网址: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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2022-01-19 c# volatile 关键字的拾遗补漏