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

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

我有一些项目有一些 exe 作为依赖";我将该项目构建为 .csproj 文件中的 nuget 包

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="CliInterface32BitInterface.exe" /> </ItemGroup> <ItemGroup> <Content Include="CliInterface32BitInterface.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="CliInterface32BitInterface.exe"> <PackageCopyToOutput>true</PackageCopyToOutput> </Content> </ItemGroup>

然后然后重新打包您的 lib 项目.当您尝试安装此新版本时,请不要忘记 先清理 nuget 缓存 或删除 C:Usersxxx(current user).nugetpackages 下的缓存文件代码>.

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:Usersxxx(current user).nugetpackages.

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

更多推荐

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

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

发布评论

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

>www.elefans.com

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