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

Copy nuget package content file (of type .exe) to output directory of project using that nuget package(使用该 nuget 包将 nuget 包内容文件(.exe 类型)复制到项目的输出目录)
本文介绍了使用该 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 类型)复制到项目的输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)