问题
I have some project which has some exe as "dependency" and I build that project as nuget package from .csproj file
File looks like this:
<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>
When I use that nuget package inside some other solution I can see file is there
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.
EDIT: 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
回答1:
Instead, try to use this
<PackageCopyToOutput>true</PackageCopyToOutput>
Add these on the csproj file:
<ItemGroup>
<Content Include="CliInterface\32BitInterface.exe">
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
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.
Besides, this is also a similar issue about this.
来源:https://stackoverflow.com/questions/65702783/copy-nuget-package-content-file-of-type-exe-to-output-directory-of-project-us