使用该nuget包将nuget包内容文件(.exe类型)复制到项目的输出目录 [英] Copy nuget package content file (of type .exe) to output directory of project using that nuget package
问题描述
我有一些项目,其某些可执行文件为"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项目.当您尝试安装此新发行版本时,请不要忘记
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
.
此外,这也是 查看全文