Home: nuget.exe pack doesn't work for legacy csproj referencing net core projects with -IncludeReferencedProjects flag

Created on 4 Dec 2016  路  27Comments  路  Source: NuGet/Home

Details about Problem

NuGet product used: nuget.exe

NuGet version: 3.5.0.1938

dotnet.exe --version: 1.0.0-preview3-004056

VS version: VS2017 RC

OS version: Windows 10

Detailed repro steps so we can see the same problem

The idea is to build two nukpgs, one depending on the other.

  1. Create a .NET Core csproj using new features such as <Compile Update=""/>

  2. Create a non-.NET Core csproj referencing the .NET Core csproj

  3. Reference the Core project from the nonCore project.

  4. dotnet pack the Core project - this succeeds.

  5. dotnet pack cannot be used for the nonCore project, so run nuget pack -IncludeReferencedProjects - this fails.

The failure is due to nuget.exe's attempt to build a MinToolsVersion=15.0 project with msbuild 14. However, there doesn't seem to be any way to get it to use the copy of msbuild 15 which VS2017rc has installed.

Logs

> dotnet pack -o ..\artifacts\ -c Debug --no-build A\A.csproj
Microsoft (R) Build Engine version 15.1.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 4/12/2016 7:23:44 PM.
     1>Project "C:\code\A\A.csproj" on node 1 (pack target(s)).
     1>GenerateNuspec:
         Successfully created package 'C:\code\artifacts\A.1.0.0.nupkg'.
     1>Done Building Project "C:\code\A\A.csproj" (pack target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.39

> NuGet pack -OutputDirectory artifacts\ -Properties Configuration=Debug -IncludeReferencedProjects B\B.csproj
Attempting to build package from 'B.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Packing files from 'C:\code\B\bin\Debug'.
The attribute "Update" in element <Compile> is unrecognized.  C:\code\A\A.csproj
Pack Backlog 1 NuGet.exe DCR

Most helpful comment

i'm still experiencing this issue with nuget 4.0.0 and .net core 1.0.0 in vs2017 rtm. it's a major blocker right now, because we have many projects where e.g. a wpf frontend depends on a netstandard library. it is not possible to pack these right now.

All 27 comments

@gulbanana our latest builds have a new command line param for the pack command :

-MSBuildPath Specifies the path of MSBuild to be used with this command. This command will take precedence over MSbuildVersion, nuget will always pick MSbuild from this specified path.

you can also use -MSBuildVersion 15 to make it pick the msbuild that comes with VS2017 RC
This should fix your problem.

you can get the latest nuget.exe from the nuget package available at : https://dotnet.myget.org/F/nuget-build/api/v2/package/NuGet.CommandLine

Great, I'll try that out

I was able to access the correct version of nuget using dotnet nuget pack from preview4.

we've yet to public 4.0rc2 nuget.exe -- which has an additional fix that shouldn't need the msbuild path to be passed in. running "dotnet nuget pack" may be running the same code path.
@rohit21agrawal - thoughts?

I'm now using nuget.exe 4.0.0.2140 from the commandline package, but it still doesn't work.

> NuGet pack -OutputDirectory artifacts\ -Properties Configuration=Debug -IncludeReferencedProjects The.Model.Editor\The.Model.Editor.csproj
Attempting to build package from 'The.Model.Editor.csproj'.
MSBuild auto-detection: using msbuild version '15.1.458.808' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Packing files from 'C:\code\framework\The.Model.Editor\bin\Debug'.
Unable to find 'bin\Debug\The.Model\bin\Debug\'. Make sure the project has been built.

The error about binDebugThe.ModelbinDebug makes me wonder whether this is a problem discovering the path of The.Model, a .NET Core project. The reference to it from The.Model.Editor looks like this:

  <ItemGroup>
    <ProjectReference Include="..\The.Model\The.Model.csproj">
      <Project>{d859ea0b-aa17-4d49-8e30-c18a03625116}</Project>
      <Name>The.Model</Name>
    </ProjectReference>

And here is The.Model.csproj itself:

<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
  <!-- Settings -->
  <PropertyGroup>
    <TargetFrameworks>net461;netstandard1.4</TargetFrameworks>
    <VersionPrefix>157.2.6</VersionPrefix>
  </PropertyGroup>

  <!-- Dependencies -->
  <ItemGroup>
    <PackageReference Include="System.Collections.Immutable" Version="1.2.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.4' ">
    <PackageReference Include="NETStandard.Library" Version="1.6.1" />
  </ItemGroup>

  <!-- Source files -->
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
  </ItemGroup>
</Project>

If I remove -IncludeReferencedProjects, I get this error instead:

Could not load file or assembly 'NuGet.resources, Version=4.0.0.2140, Culture=en-GB, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
  Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\en\NuGet.resources.dll' or one of its dependencies. The system cannot find the file specified.

@gulbanana - you should use nuget.exe for non NetCore projects and dotnet.exe for netcore projects

That is what I am doing, but nuget.exe does not work to pack a noncore project which depends on a core/netstandard project.

@gulbanana - I ll look into this, I would really appreciate if you attached a small repro project that highlights the issue

Ok, I will be able to supply a repro tomorrow.

I've actually found at least three separate issues, so this is going to be spread across a couple of posts..
Here is the first repro: https://github.com/gulbanana/repro-nuget-pack-p2p

netfxlib depends on netstdlib. netstdlib packs correctly:

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netstdlib (master)
$ dotnet --version
1.0.0-preview4-004233

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netstdlib (master)
$ dotnet pack
Microsoft (R) Build Engine version 15.1.458.808
Copyright (C) Microsoft Corporation. All rights reserved.

  netstdlib -> C:\code\repro-nuget-pack-p2p\netstdlib\bin\Debug\netstandard1.4\netstdlib.dll

netfxlib pack fails to IncludeReferencedProjects:

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netfxlib (master)
$ nuget | grep Version
NuGet Version: 4.0.0.2140

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netfxlib (master)
$ nuget pack -IncludeReferencedProjects
Attempting to build package from 'netfxlib.csproj'.
MSBuild auto-detection: using msbuild version '15.1.458.808' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Packing files from 'C:\code\repro-nuget-pack-p2p\netfxlib\bin\Debug'.
Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGetFramework'.

And if -IncludeReferencedProperties is not specified, nuget 4.0 emits a different error:

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netfxlib (master)
$ nuget pack
Attempting to build package from 'netfxlib.csproj'.
MSBuild auto-detection: using msbuild version '15.1.458.808' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Packing files from 'C:\code\repro-nuget-pack-p2p\netfxlib\bin\Debug'.
WARNING: Description was not specified. Using 'Description'.
WARNING: Author was not specified. Using 'banana'.
Could not load file or assembly 'NuGet.resources, Version=4.0.0.2140, Culture=en-GB, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
  Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\en\NuGet.resources.dll' or one of its dependencies. The system cannot find the file specified.

The multitarget branch demonstrates a different issue, the one I first experienced in real code: https://github.com/gulbanana/repro-nuget-pack-p2p/tree/multitarget

netstdlib2 packs correctly:

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netstdlib2 (multitarget)
$ dotnet pack
Microsoft (R) Build Engine version 15.1.458.808
Copyright (C) Microsoft Corporation. All rights reserved.

  netstdlib2 -> C:\code\repro-nuget-pack-p2p\netstdlib2\bin\Debug\net461\netstdlib2.dll
  netstdlib2 -> C:\code\repro-nuget-pack-p2p\netstdlib2\bin\Debug\netstandard1.4\netstdlib2.dll

netfxlib2 fails to pack:

banana@forsyth MINGW64 /c/code/repro-nuget-pack-p2p/netfxlib2 (master)
$ nuget pack -IncludeReferencedProjects
Attempting to build package from 'netfxlib2.csproj'.
MSBuild auto-detection: using msbuild version '15.1.458.808' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Packing files from 'C:\code\repro-nuget-pack-p2p\netfxlib2\bin\Debug'.
Unable to find 'bin\Debug\netstdlib2\bin\Debug\'. Make sure the project has been built.

@gulbanana while i can repro the cases using your branch (both master and multitarget) for nuget pack -includereferencedprojects case, the scenario for vanila nuget pack (without includereferencedprojects flag) works fine on my machine.

i'd try repairing your installation of visual studio to make sure all the DLLs are in the right place.

Important to do, but won't be done by VS2017. Should consider immediately after.

:( This is going to block vs2017 for us, then. Will there really be no way to create nupkgs depending on netstandard projects before vs2018/19?

@gulbanana we will ship an update to NuGet much before the next version of NuGet. You won't have to wait too long

OK, that's a relief.

i'm still experiencing this issue with nuget 4.0.0 and .net core 1.0.0 in vs2017 rtm. it's a major blocker right now, because we have many projects where e.g. a wpf frontend depends on a netstandard library. it is not possible to pack these right now.

Is there any further discussion being had on this? I am still seeing the issue in nuget 4.3.0.4 and

I have another repro here: https://github.com/acinep/nuget-pack-repro

nuget pack ClassicLibrary -IncludeReferencedProjects

Unable to cast object of type 'System.String' to type 'NuGet.Frameworks.NuGet.Frameworks1048373.NuGetFramework'.

I am also seeing this behavior with our legacy projects. Blocks us from moving our library code to .NET standard as preparation for future upgrades.

Getting the same error using NuGet 4.4 on VSTS build.
Any fix or workaround for VSTS?

2017-10-25T00:51:34.3884127Z ##[section]Starting: NuGet pack
2017-10-25T00:51:34.3894133Z ==============================================================================
2017-10-25T00:51:34.3894133Z Task : NuGet
2017-10-25T00:51:34.3894133Z Description : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
2017-10-25T00:51:34.3894133Z Version : 2.0.12
2017-10-25T00:51:34.3894133Z Author : Microsoft Corporation
2017-10-25T00:51:34.3894133Z Help : More Information
2017-10-25T00:51:34.3894133Z ==============================================================================
2017-10-25T00:51:34.7744129Z [command]C:Windowssystem32chcp.com 65001
2017-10-25T00:51:34.7804130Z Active code page: 65001
2017-10-25T00:51:34.8014119Z Attempting to pack file: d:a1s___.csproj
2017-10-25T00:51:34.8054119Z [command]d:a_toolNuGet4.4.0x64nuget.exe pack d:a1s___.csproj -NonInteractive -OutputDirectory d:a1a -Properties Configuration=release -Verbosity Detailed
2017-10-25T00:51:35.2294130Z NuGet Version: 4.4.0.4475
2017-10-25T00:51:35.2344134Z Attempting to build package from ___.csproj'.
2017-10-25T00:51:35.2714237Z MSBuild auto-detection: using msbuild version '14.0' from 'C:Program Files (x86)MSBuild14.0binamd64'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
2017-10-25T00:51:35.3114135Z The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. d:a1s___.csproj
2017-10-25T00:51:35.3252813Z Microsoft.Build.Exceptions.InvalidProjectFileException: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. d:a1s___.csproj
2017-10-25T00:51:35.3252813Z at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
2017-10-25T00:51:35.3252813Z at Microsoft.Build.Construction.ProjectParser.Parse()
2017-10-25T00:51:35.3252813Z at Microsoft.Build.Construction.ProjectParser.Parse(XmlDocumentWithLocation document, ProjectRootElement projectRootElement)
2017-10-25T00:51:35.3252813Z at Microsoft.Build.Construction.ProjectRootElement..ctor(String path, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
2017-10-25T00:51:35.3252813Z at Microsoft.Build.Construction.ProjectRootElement.CreateProjectFromPath(String projectFile, IDictionary2 globalProperties, String toolsVersion, ILoggingService loggingService, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext) 2017-10-25T00:51:35.3252813Z at Microsoft.Build.Construction.ProjectRootElement.<>c__DisplayClass170_0.<OpenProjectOrSolution>b__0(String path, ProjectRootElementCache cache) 2017-10-25T00:51:35.3252813Z at Microsoft.Build.Evaluation.ProjectRootElementCache.Get(String projectFile, OpenProjectRootElement openProjectRootElement, Boolean isExplicitlyLoaded) 2017-10-25T00:51:35.3252813Z at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
2017-10-25T00:51:35.3252813Z at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion)
2017-10-25T00:51:35.3362960Z ##[error]Error: d:a_toolNuGet4.4.0x64nuget.exe failed with return code: 1
2017-10-25T00:51:35.3362960Z ##[error]An error ocurred while trying to pack the files.
2017-10-25T00:51:35.3412947Z ##[section]Finishing: NuGet pack

Also got this error.
NuGet Version: 4.4.1.4656
First library(First.csproj) - netstandard1.3
Second library(Second.csproj) - .Net framework 4.6.1
Second.csproj has project reference on First.csproj.
nuget pack Second.csproj -IncludeReferencedProjects fails with error

Error occurred when processing file 'E:\blabla\First.csproj': Unable to find 'bin\Release\First\bin\Release\'. Make sure the project has been built.
  Unable to find 'bin\Release\First\bin\Release\'. Make sure the project has been built.

Ugly workaround:
1) manually add dependency on package of First.csproj into .nuspec file of Second.csproj

   <dependencies>
      <dependency id="First" version="actual version of First here" />
    </dependencies>

2) use nuget pack without flag -IncludeReferencedProjects

@acinep how did you solve this? I'm running against the exact same issue here...
I temporarily solved it by adding the .net standard output in the referencing projects _nuspec_ <file> tag..

Not related to a dotnetcore project, but we had issues similar to some of those described above trying to pack a project (.csproj) that referenced other projects with -IncludeReferencedProjects where there were nuget packages referenced anywhere in the chain of referenced projects.

We got the error Unable to find '<some nuget package>'. Make sure the project has been built., when running nuget pack from our Solution directory even though the supposedly missing packages were in our repositoryPath from our nuget.config (Solutionpackages).

A little bit of experimentation revealed that during nuget pack, the nuget packages referenced in packages.config files for the various projects in the chain were being searched for local/relative to the location of either the project being referenced or the packages.config for that project (same directory), instead of the directory where we've installed all of the nuget packages.

A hacky workaround that we put in place in our msbuild .proj file was to execute a task before the nuget pack Exec task to create symbolic links creating a .packages symlink in each of the project directories to simulate each of them having a packages subdirectory, each of which just pointed to Solutionpackages.

    <ItemGroup>
      <ProjectDir Include="." />
      <ProjectDir Include="..\OtherProjectDir" />
      <ProjectDir Include="..\YetAnotherProjectDirReferencedByTheProjectInProjectDir" />
        ...
    </ItemGroup>
    <!-- for each one, make the symbolic link -->
    <Exec
      Command="mklink /D %(ProjectDir.FullPath)\packages ..\Solution\packages"
      IgnoreExitCode="true"
    />

    <!-- Run the nuget pack command -->
    <Exec
      Command="Solution\.nuget\nuget.exe pack 'ProjectDir\Project.csproj' -IncludeReferencedProjects -OutputDirectory $(Configuration)\Nupkg -properties Configuration=$(Configuration);Author=MyCompany;Description=MyCompany"
      WorkingDirectory="..\"
     />

    <!-- remove the symbolic links we created previous to running the pack command -->
    <Exec
      Command="rmdir %(ProjectDir.FullPath)\packages"
      IgnoreExitCode="true"
    />     

Hi @gulbanana,

I'm facing the same issue. I have a .NET standard 2.0 project and a .NET 4.61 which depends on the first.

Error NU5012: Unable to find 'bin\Release\MyProject\bin\Release\'. Make sure the project has been built.
An error occurred when executing task 'Pack'.
Error: One or more errors occurred.
NuGet: Process returned an error (exit code 1).

NuGet Version: 5.0.2.5988

Do you have any recommended workaround to have this working?

Still a problem in latest version (as of today) 5.5.0 (preview) https://www.nuget.org/downloads

Is there a workaround that packs a *.csproj project file, and includes references to other packages from the referenced projects?
(without packing a *.nuspec file that references them)?

Any update on this? I am facing same issue when I'm trying to pack non-sdk project that references netstandard2.0.

Was this page helpful?
0 / 5 - 0 ratings