Home: nuget pack looks for files at wrong place for multitarget csproj

Created on 31 Aug 2017  路  16Comments  路  Source: NuGet/Home

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):

NuGet version (4.1.0.2450):

dotnet.exe --version (if appropriate): n/a

VS version (if appropriate): 15.3.3 (2017 Enterprise)

OS version (i.e. win10 v1607 (14393.321)): win10 x64 v1703 (15063.483)

Worked before? If so, with which NuGet version: unknown

Detailed repro steps so we can see the same problem

  1. Create a new c# Class Library (.NET Standard) project targeting netstandard2.0.

  2. Edit the csproj file to add target frameworks net4, netstandard1.3:
    <TargetFrameworks>net4;netstandard1.3;netstandard2.0</TargetFrameworks>

  3. Set GeneratePackageOnBuild property to true:
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>

  4. Build and pack with VS or msbuild (to check the build passes and package is created):
    nuget restore
    msbuild test.csproj /t:Clean,Build,Pack /p:Configuration=Release

  5. (Optional) The property GeneratePackageOnBuild can be set to false, but result is the same.

  6. Try to build package with nuget:
    nuget pack test.csproj -Build -p Configuration=Release

    which fails with an error:

    Could not find a part of the path 'C:Projects\Test\bin\Release\Test\bin\Release'.

Other suggested things

n/a

Verbose Logs

C:Projects\Test>nuget pack Test.csproj -Build -p Configuration=Release -verbosity detailed
NuGet Version: 4.1.0.2450
Attempting to build package from 'Test.csproj'.
MSBuild auto-detection: using msbuild version '15.3.409.57025' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 8/31/2017 4:33:49 PM.
Project "C:Projects\Test\Test.csproj" on node 1 (default targets).
--- snip ---
Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.99
Packing files from 'C:Projects\Test\bin\Release\Test\bin\Release'.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:Projects\Test\bin\Release\Test\bin\Release'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
at NuGet.CommandLine.ProjectFactory.GetFiles(String path, ISet`1 fileNames, SearchOption searchOption)
at NuGet.CommandLine.ProjectFactory.AddOutputFiles(PackageBuilder builder)
at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
at NuGet.CommandLine.PackCommand.ExecuteCommand()
at NuGet.CommandLine.Command.ExecuteCommandAsync()
at NuGet.CommandLine.Command.Execute()
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

Sample Project

test.zip

Pack Question

Most helpful comment

@mm6502 nuget.exe doesn't have support to pack NETCore projects yet.

Hi @rohit21agrawal, the comment I've quoted was from August 2017. Is there any update on this? Are there any plans to add support for .NetCore or .NetStandard projects?

I'm not using GeneratePackageOnBuild, and have now run into this issue when attempting to add multi-targeting into my project.

All 16 comments

@mm6502 nuget.exe doesn't have support to pack NETCore projects yet.

if you are setting GeneratePackageOnBuild to true , then you don't need to call the pack target separately.

@rohit21agrawal It is not a NETCore project. It is a netstandard project. (At least by the VS project template description.)

That may be true. But it seems like a bug to me, anyway. Still, I would prefer the nuget way, since I have to call it anyway to restore packages before build; and want to build a Symbols package. (I do not know how to do it with msbuild.)

to restore you can do msbuild /t:restore , and to create symbols package you can do msbuild /t:pack /p:IncludeSymbols=true .

@mm6502 let me know if that worked for you and i will close this issue.

Thanks. That should solve my problem. Unfortunately, earliest I can try on monday.

sure, no worries. also, please note that whenever GeneratePackageOnBuild is set to true, you shouldn't call the pack task directly as it skips building to avoid a circular dependency between targets.

@rohit21agrawal restore and pack works with compiled content.

Off topic:
Now only to figure out how to handle framework specific content (t4 templates)...

Glad to hear this has been addressed. Thanks.

Seems like <GeneratePackageOnBuild>true</GeneratePackageOnBuild> doesn't work when building with VisualStudio for Mac (using 7.3, last version). Any recommendation in this case?

(With "doesn't work" I mean I don't see any .nupkg file in the subfolders underneath bin/Debug ...)

Just to clarify the solution to this is to use msbuild pack?

@hack2root @mattwhetton what is the problem you are facing exactly? Please understand that we get a lot of comments on GitHub, and comments on closed issues aren't prioritized as much. If you are still facing an issue that has been closed, please open a new one with all the details.

@rohit21agrawal I can't open it, for some reason.

please open a new one at github.com/nuget/home/issues

I also ran into this issue when attempting to create a NuGet package for a netstandard project using nuget pack.

In my case, I needed to rebuild an existing netstandard project to support .NET Framework 4.5.2 and could not use msbuild.

The solution for me was to create a new .NET Framework project targeting 4.5.2 and copy everything over from the pre-existing project and fix the build errors. Then I was able to use nuget pack on the newly created project without getting this issue.

@mm6502 nuget.exe doesn't have support to pack NETCore projects yet.

Hi @rohit21agrawal, the comment I've quoted was from August 2017. Is there any update on this? Are there any plans to add support for .NetCore or .NetStandard projects?

I'm not using GeneratePackageOnBuild, and have now run into this issue when attempting to add multi-targeting into my project.

Was this page helpful?
0 / 5 - 0 ratings