question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet pack uses wrong path for obj artifact and fails on Preview5

See original GitHub issue

Executing dotnet pack in a project directory with a P2P dependency tries to pack using an incorrect artifact path:

error MSB4018: The "PackTask" task failed unexpectedly.
error MSB4018: System.IO.FileNotFoundException: File not found: 'C:\bitbucket\fx\Fx-Core\src\Fx.Core\obj\Debug\Fx.Core.dll'.
error MSB4018:    at NuGet.Packaging.PackageBuilder.AddFiles(String basePath, String source, String destination, String exclude)
error MSB4018:    at NuGet.Packaging.PackageBuilder.PopulateFiles(String basePath, IEnumerable`1 files)
error MSB4018:    at NuGet.Commands.MSBuildProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
error MSB4018:    at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
error MSB4018:    at NuGet.Commands.PackCommandRunner.BuildPackage(String path)
error MSB4018:    at NuGet.Commands.PackCommandRunner.BuildPackage()
error MSB4018:    at NuGet.Build.Tasks.Pack.PackTask.Execute()
error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() 

My project file is as such:

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
  <Import Project="..\..\SharedProperties.props" />
  <PropertyGroup Label="Configuration">
    <RootNamespace>Fx</RootNamespace>
  </PropertyGroup>
  <PropertyGroup>
    <Description>Core library</Description>
    <Copyright>Fresh Egg Limited</Copyright>
    <AssemblyTitle>FX: Core</AssemblyTitle>
    <TargetFramework>netstandard1.6</TargetFramework>
    <AssemblyName>Fx.Core</AssemblyName>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <Compile Include="..\..\SharedVersionInfo.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Authorization">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Json">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.DependencyModel">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.FileProviders.Composite">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.PlatformAbstractions">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="NETStandard.Library">
      <Version>1.6.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Fx.Common\Fx.Common.csproj" />
    <ProjectReference Include="..\Fx.Core.Abstractions\Fx.Core.Abstractions.csproj" />
    <ProjectReference Include="..\Fx.Data.Abstractions\Fx.Data.Abstractions.csproj" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

The generated spec file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>Fx.Core</id>
    <version>1.0.0</version>
    <authors>Fx.Core</authors>
    <owners>Fx.Core</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Core library</description>
    <copyright>Fresh Egg Limited</copyright>
    <dependencies>
      <group targetFramework=".NETStandard1.6">
        <dependency id="Fx.Common" version="1.0.0" exclude="Build,Analyzers" />
        <dependency id="Fx.Core.Abstractions" version="1.0.0" exclude="Build,Analyzers" />
        <dependency id="Fx.Data.Abstractions" version="1.0.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Authentication" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Authorization" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Diagnostics" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Mvc" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.StaticFiles" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.EntityFrameworkCore" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Configuration.Binder" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Configuration.EnvironmentVariables" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Configuration.Json" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.DependencyModel" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.FileProviders.Composite" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.FileProviders.Embedded" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.PlatformAbstractions" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="NETStandard.Library" version="1.6.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="C:\bitbucket\fx\Fx-Core\src\Fx.Core\obj\Debug\netstandard1.6\Fx.Core.dll" target="lib\netstandard1.6\Fx.Core.dll" />
    <file src="C:\bitbucket\fx\Fx-Core\src\Fx.Core\obj\Debug\Fx.Core.dll" target="lib\Fx.Core.dll" />
  </files>
</package>

Observations:

  1. If I attempt to dotnet pack my Fx.Common project which has no P2P dependencies, it packs fine.
  2. If I attempt to pack any of my other projects which have P2P dependencies, the pack fails.
  3. The pack command looks to be looking for /obj/{Configuration}/{OutputFilename}.dll instead of /obj/{Configuration}/{Framework}/{OutputFilename}.dll.
  4. There are two references to Fx.Core.dll in the spec file, is this correct?

Environment data

.NET Command Line Tools (1.0.0-preview5-004226)

Product Information:
 Version:            1.0.0-preview5-004226
 Commit SHA-1 hash:  7b109e4b53

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0-preview5-004226

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
JoseFMPcommented, Jun 23, 2017

Experiencing same issue… 2.0.0-preview1-005977

0reactions
Antariscommented, Jan 19, 2017

@piotrpMSFT This problem seems to have disappeared now I am using 1.0.0-preview5-004275, closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet pack not including build artifacts
I've tried deleting the obj folder (where I believe nuget temporarily stores the artifacts), deleted the output etc. and I can't get the...
Read more >
dotnet pack command - .NET CLI
The dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package (that is, a...
Read more >
What's new in .NET 8
Learn about the new .NET features introduced in .NET 8. ... returns false if no metadata for the specified type was found.
Read more >
NuGet Error NU5049
The `pack` command for SDK-style projects is not supported, use `dotnet pack` or `msbuild -t:pack` to pack this project instead.
Read more >
Create a NuGet package using MSBuild
A detailed guide to the process of designing and creating a NuGet package using MSBuild, including key decision points like files and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found