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" attempting to create package from undesired \bin\Debug .dll assembly #7079

Closed
chiefengineer opened this issue Jul 1, 2018 · 2 comments
Labels
Functionality:Pack Resolution:Question This issues appears to be a question, not a product defect

Comments

@chiefengineer
Copy link

chiefengineer commented Jul 1, 2018

Details about Problem

Nuget.exe
version 4.6.2.5055
VS version (if appropriate):
2017 15.7.4 Enterprise
OS version (i.e. win10 v1607 (14393.321)):
17134.137 (1803 from 5/2/2018)

Worked before? If so, with which NuGet version:

Yes. Don't know when it broke.

Detailed repro steps so we can see the same problem

  1. Execute the following at a command prompt (as a single line, of course):
    nuget pack "C:\Users\Sam\Documents\Visual Studio 2017\Projects\DotNet_4.7\AWE 9.x\AWE.Lib.Root\Cmn\Cmn.csproj" -ExcludeEmptyDirectories -IncludeReferencedProjects - OutputDirectory "C:\Users\Sam\AppData\Roaming\NuGet\PackageHome\AWE.Lib.Root\AWE.Lib.Root.Cmn\9.0.0.1\" -Verbosity detailed

  2. Receive the following:
    NuGet Version: 4.6.2.5055
    Attempting to build package from 'Cmn.csproj'.
    MSBuild auto-detection: using msbuild version '15.7.179.6572' 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.
    Unable to find 'C:\Users\Sam\Documents\Visual Studio 2017\Projects\DotNet_4.7\AWE 9.x\AWE.Lib.Root\Cmn\bin\Debug\AWE.Lib.Root.Cmn.dll'. Make sure the project has been built.
    NuGet.CommandLine.CommandLineException: Unable to find 'C:\Users\Sam\Documents\Visual Studio 2017\Projects\DotNet_4.7\AWE 9.x\AWE.Lib.Root\Cmn\bin\Debug\AWE.Lib.Root.Cmn.dll'. Make sure the project has been built.
    at NuGet.CommandLine.ProjectFactory.BuildProject()
    at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
    at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
    at NuGet.Commands.PackCommandRunner.BuildPackage()
    at NuGet.CommandLine.PackCommand.ExecuteCommand()
    at NuGet.CommandLine.Command.ExecuteCommandAsync()
    at NuGet.CommandLine.Command.Execute()
    at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)


Before I get carried away and paste an entire project in here (it's simple, just a placeholder for some constants, Full Framework 4.7.2, I want to know why the following:

  1. If the DEBUG version of the project has NOT been built, then the above message is returned. As in why, when trying to pack a RELEASE version of the project, is MSBuild looking for a DEBUG .dll to scan and for that matter, why is MSBuild involved at all? I didn't request a build here (THERE IS NO "-Build" in the command line), just a pack of what should be an already-existing (and it does) RELEASE .dll.

  2. If the DEBUG version DOES exists, I get the following from the same exact command line:
    NuGet Version: 4.6.2.5055
    Attempting to build package from 'Cmn.csproj'.
    MSBuild auto-detection: using msbuild version '15.7.179.6572' 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.
    Packing files from 'C:\Users\Sam\Documents\Visual Studio 2017\Projects\DotNet_4.7\AWE 9.x\AWE.Lib.Root\Cmn\bin\Debug'.
    Add file 'C:\Users\Sam\Documents\Visual Studio 2017\Projects\DotNet_4.7\AWE 9.x\AWE.Lib.Root\Cmn\bin\Debug\AWE.Lib.Root.Cmn.dll' to package as 'lib\net472\AWE.Lib.Root.Cmn.dll'

Id: AWE.Lib.Root.Cmn
Version: 9.0.0.1-FredWasHere
Authors: The Company
Description: You didn't update the AssemblyDescription!
Dependencies:

Added file '[Content_Types].xml'.
Added file '_rels/.rels'.
Added file 'AWE.Lib.Root.Cmn.nuspec'.
Added file 'lib/net472/AWE.Lib.Root.Cmn.dll'.
Added file 'package/services/metadata/core-properties/84680d37163549ff9565ecf5fa83618e.psmdcp'.

Successfully created package 'C:\Users\Sam\AppData\Roaming\NuGet\PackageHome\AWE.Lib.Root\AWE.Lib.Root.Cmn\9.0.0.1\AWE.Lib.Root.Cmn.9.0.0.1-FredWasHere.nupkg'.


Notice the MSBuild is looking for a Debug version (\bin\Debug) to build. Don't know why. Is this where the mysterious "BasePath" option might help? I wouldn't know because the definition and explanation given by both the application and the documentation are worse then useless - they don't TELL me anything. Just for kicks, I added a complete path to the release directory of the project, same error.

Again, why is MSBuild involved here at all as I did not request a build and why is the DEBUG version being referenced? I can tell because my AssemblyInfo.cs linked file (see below) has the debug information version extension "FredWasHere" as a version suffix, but again, I'm ASKING FOR A RELEASE pack, NOT a DEBUG!

And...why is the pack command looking in the \bin\Debug folder?!

Here is the content of my AssemblyInfo.cs and following, the SolutionAssemblyInfo.cs linked files:

This error occurs regardless of the existence of a corresponding .nuspec file.

--AssemblyInfo.cs:

using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SolutionAssemblyInfoNuGetReady")]
[assembly: AssemblyDescription("You didn't update the AssemblyDescription!")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d0208727-2016-4de3-9528-c7ef3641b5b4")]

...and the corresponding linked file SolutionAssemblyInfo:

using System.Reflection;
using static AssemblyInfoConsts;

[assembly: AssemblyCompany(COMPANY)]
[assembly: AssemblyProduct("AWE.Lib")]
[assembly: AssemblyCopyright("Copyright © 2016 " + COMPANY)]
[assembly: AssemblyTrademark("The Trademwrk")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// Revision Numbers by using the '' as shown below:
// [assembly: AssemblyVersion("1.0.
")]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyVersion(VERSION + BUILD_V)]
[assembly: AssemblyFileVersion(VERSION + BUILD_FV)]
[assembly: AssemblyInformationalVersion(VERSION + BUILD_V + BUILD_I)] // NuGet $version$
#else
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyVersion(VERSION + BUILD_V)]
[assembly: AssemblyFileVersion(VERSION + BUILD_FV)]
[assembly: AssemblyInformationalVersion(VERSION + BUILD_V)] // NuGet $version$
#endif
internal struct AssemblyInfoConsts
{
internal const string VERSION = "9.0.0.";
internal const string BUILD_FV = "1"; // This value needs to be AT LEAST 1, otherwise NuGet has "trouble" with it (it ignores it entirely).
internal const string BUILD_V = BUILD_FV;
internal const string BUILD_I = "-FredWasHere"; // Set this to an empty string if a debug version is needed in NuGet
internal const string COMPANY = "The Company";
}


And here is the content of the .csproj file:
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{D0208727-2016-4DE3-9528-C7EF3641B5B4}</ProjectGuid> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>AWE.Lib.Root</RootNamespace> <AssemblyName>AWE.Lib.Root.Cmn</AssemblyName> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="Microsoft.CSharp" /> </ItemGroup> <ItemGroup> <Compile Include="..\..\AWE.Lib.SolutionAssemblyInfo.cs"> <Link>Properties\AWE.Lib.SolutionAssemblyInfo.cs</Link> </Compile> <Compile Include="BaseDisposable.cs" /> <Compile Include="ConstsAndEnums.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> <None Include="ReleaseNotes.txt" /> <None Include="Summary.txt" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PostBuildEvent>@echo off IF NOT $(ConfigurationName) == Release GOTO NOT_RELEASE REM IF EXIST "$(SolutionDir)CopyToT4Support.bat" CALL "$(SolutionDir)CopyToT4Support" "$(TargetPath)" "$(SolutionDir)" IF NOT EXIST "%25VSProjectsDir%25NuGetHandler.bat" GOTO DIRECT CALL "%25VSProjectsDir%25NuGetHandler.bat" "$(TargetPath)" "$(SolutionPath)" "$(ProjectPath)" $(ConfigurationName) GOTO END :DIRECT IF NOT EXIST "%25APPDATA%25\NuGet\win10-x64\NuGetHandler.dll" GOTO END dotnet "%25APPDATA%25\NuGet\win10-x64\NuGetHandler.dll" -t "$(TargetPath)" -s "$(SolutionPath)" -p "$(ProjectPath)" -c $(ConfigurationName) GOTO END :NOT_RELEASE GOTO END :END </PostBuildEvent> </PropertyGroup> </Project>


The Post-Build script just calls a gadget that executes NuGet.exe for me post build so that said package is automatically sent to one or more NuGet.Server servers. One will notice, however, that even this script is invoked only in Release mode. Nothing should happen in Debug mode. But the problem persists if the resulting command line is called straight from a command prompt. Makes no difference if spawned from within the handler or from the command line, nuget.exe still does not do what I need it to do.

I'm really hoping that it's something dumb that I have/have not done and that the fix is an easy one. But, given what I've seen in the documentation, it won't be.

Just as a final note, this is a show-stopper for me. I cannot progress with my development until this is fixed. I have a library with some 88+ packages that all need to live in NuGet.Servers for the rest of the Supreme Court to access for development, plus a gadget that needs to go into production in a month for advanced db development that I now cannot work on. So...an answer would be extremely appreciated!

Update: I see from this quote in issue #6979 :

"@dkalkwarf can you paste your csproj here? Is this a netcore project or a full framework project? nuget pack, by default, looks for debug bits, unless otherwise specified."

that NuGet can be told to look in an alternate directory (although I cannot imagine for the life of me why nuget would be specifically looking for DEBUG info, especially by default!). OK, HOW? Please list all the various ways such a redirect to RELEASE code can be accomplished and please accompany that with a reference in the documentation that elaborates on the process.

Second Update: OK, figured out how to tell nuget pack to use the Release build: Add a properties flag thusly:

-Properties "Configuration=Release"

does the trick. I could wish that the documentation was just a little clearer on that point.

@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Jul 2, 2018

@chiefengineer the reason nuget looks for debug bits to pack by default is the same as why msbuild builds debug bits by default if you just run msbuild on your project.

These defaults were chosen because in the inner development loop, developers build non-optimised debug bits making it easy for them to step through code for debugging purposes.

You can, of course, set the property in your csproj <Configuration>Release</Configuration> and that would make nuget and msbuild use release configurations by default.

@rohit21agrawal rohit21agrawal added the Resolution:Question This issues appears to be a question, not a product defect label Jul 2, 2018
@nkolev92
Copy link
Member

nkolev92 commented Jul 2, 2018

Closing this per Rohit's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Pack Resolution:Question This issues appears to be a question, not a product defect
Projects
None yet
Development

No branches or pull requests

3 participants