1

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 enter image description here

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

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
Vlado Pandžić
  • 4,879
  • 8
  • 44
  • 75

1 Answers1

4

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.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • This should be default option. What is the point of gaving content files which don't end up in output folder. And tnx :) – Vlado Pandžić Jan 14 '21 at 12:00
  • 1
    `PackageCopyToOutput` is for the content files from nuget packages being copied into the output folders pf the main project while `CopyToOutputDirectory` is for the internal files of the main projects being copied into the output folder. – Mr Qian Jan 15 '21 at 01:50