使用该nuget包将nuget包内容文件(.exe类型)复制到项目的输出目录

编程入门 行业动态 更新时间:2024-10-10 16:18:39
本文介绍了使用该nuget包将nuget包内容文件(.exe类型)复制到项目的输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些项目,其某些可执行文件为"dependency",即"dependency".然后我从 .csproj 文件

I have some project which has some exe as "dependency" and I build that project as nuget package from .csproj file

文件如下:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <Nullable>enable</Nullable> <LangVersion>latest</LangVersion> <Version>1.1.2</Version> <PackageId>MyLib</PackageId> <Authors>me</Authors> <Company>me</Company> </PropertyGroup> <ItemGroup> <None Remove="CliInterface\32BitInterface.exe" /> </ItemGroup> <ItemGroup> <Content Include="CliInterface\32BitInterface.exe"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0"> <PrivateAssets>analyzers;build</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> </Project>

当我在其他解决方案中使用该nuget包时,我可以看到文件在那里

When I use that nuget package inside some other solution I can see file is there

但是它不会复制到输出文件夹.实际上,正确的是当我从Visual Studio 运行 Build 项目时,但是我在 CI中使用了 dotnet build 命令/CD 环境,并且在运行该命令时不会将其复制到输出中.

However it is not copyed to output folder. In fact, to be correct it is when I run Build project from Visual Studio, but I use dotnet build command in my CI/CD environment and it is not copied to output when I run that command.

我还注意到该exe的位置位于%USERPROFILE%.nuget文件夹内而且我的csproj文件(从其他解决方案中引用了nuget包)具有经过硬编码的路径,其中包含我的用户名.我不确定为什么会这样,但是不喜欢这样

I also noticed that location of that exe is inside %USERPROFILE%.nuget folder and also my csproj file (from other solution, that references that nuget package) has hardocoded path with my username inside it. I'm not sure why is that the case but don't like that

推荐答案

相反,请尝试使用此

< PackageCopyToOutput> true</PackageCopyToOutput>

添加:

<ItemGroup> <Content Include="CliInterface\32BitInterface.exe"> <PackageCopyToOutput>true</PackageCopyToOutput> </Content> </ItemGroup>

然后,然后重新打包您的lib项目.当您尝试安装此新发行版本时,请不要忘记先清理nuget缓存,或删除 C:\ Users \ xxx(当前用户)\.nuget \ packages下的缓存文件代码>.

And then repack your lib project. When you try to install this new release version, please do not forget to clean nuget caches first or delete cache files under C:\Users\xxx(current user)\.nuget\packages.

此外,这也是与此类似的问题.

更多推荐

使用该nuget包将nuget包内容文件(.exe类型)复制到项目的输出目录

本文发布于:2023-11-14 14:18:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   文件   目录   项目   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!