Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gulbanana opened this issue Dec 4, 2016 · 28 comments
Labels
Functionality:Pack Priority:2 Issues for the current backlog. Product:NuGet.exe NuGet.exe Type:DCR Design Change Request
Milestone

Comments

@gulbanana
Copy link

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
@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Dec 15, 2016

@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

@gulbanana
Copy link
Author

Great, I'll try that out

@gulbanana
Copy link
Author

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

@rrelyea
Copy link
Contributor

rrelyea commented Dec 19, 2016

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?

@gulbanana gulbanana reopened this Dec 20, 2016
@gulbanana
Copy link
Author

gulbanana commented Dec 20, 2016

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 bin\Debug\The.Model\bin\Debug\ 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>

@gulbanana
Copy link
Author

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.

@rohit21agrawal
Copy link
Contributor

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

@gulbanana
Copy link
Author

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

@rohit21agrawal
Copy link
Contributor

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

@gulbanana
Copy link
Author

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

@gulbanana
Copy link
Author

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.

@gulbanana
Copy link
Author

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.

@rohit21agrawal
Copy link
Contributor

@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.

@rohit21agrawal rohit21agrawal changed the title Nuget Pack fails for non-Core project referencing Core project which uses msbuild 15 features nuget.exe pack doesn't work for legacy csproj referencing net core projects with -IncludeReferencedProjects flag Dec 21, 2016
@rrelyea rrelyea modified the milestones: 4.0.1, 4.0 RC3 Jan 5, 2017
@rrelyea
Copy link
Contributor

rrelyea commented Jan 5, 2017

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

@gulbanana
Copy link
Author

:( 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?

@rohit21agrawal
Copy link
Contributor

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

@gulbanana
Copy link
Author

OK, that's a relief.

@rohit21agrawal rohit21agrawal added Type:DCR Design Change Request Product:NuGet.exe NuGet.exe labels Jan 27, 2017
@zhili1208 zhili1208 modified the milestones: Future-0, 4.5, Backlog Oct 17, 2017
@nkolev92 nkolev92 added the Priority:1 High priority issues that must be resolved in the current sprint. label Oct 17, 2017
@LTsLlama
Copy link

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:\Windows\system32\chcp.com 65001
2017-10-25T00:51:34.7804130Z Active code page: 65001
2017-10-25T00:51:34.8014119Z Attempting to pack file: d:\a\1\s_.csproj
2017-10-25T00:51:34.8054119Z [command]d:\a_tool\NuGet\4.4.0\x64\nuget.exe pack d:\a\1\s_
.csproj -NonInteractive -OutputDirectory d:\a\1\a -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)\MSBuild\14.0\bin\amd64'. 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:\a\1\s_
.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:\a\1\s_
_.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_tool\NuGet\4.4.0\x64\nuget.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

@Frank591
Copy link

Frank591 commented Nov 21, 2017

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>
  1. use nuget pack without flag -IncludeReferencedProjects

@bickycheese
Copy link

bickycheese commented Apr 2, 2018

@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..

@domehead100
Copy link

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 (\Solution\packages).

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 \Solution\packages.

    <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"
    />     

@laura-rodriguez
Copy link

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?

@jezzsantos
Copy link

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)?

@roofiq
Copy link

roofiq commented Dec 22, 2020

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

@jyeagle
Copy link

jyeagle commented Apr 13, 2021

I am also experiencing this issue :(

@nkolev92 nkolev92 added Priority:2 Issues for the current backlog. and removed Priority:1 High priority issues that must be resolved in the current sprint. labels Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Pack Priority:2 Issues for the current backlog. Product:NuGet.exe NuGet.exe Type:DCR Design Change Request
Projects
None yet
Development

No branches or pull requests