Build not packaging module

Issue #101 new
Shawn Melton created an issue
VS 2019 CE
PoshTools version 4.2.2


Name                           Value                                                                                                                                
----                           -----                                                                                                                                
PSVersion                      5.1.17134.590                                                                                                                        
PSEdition                      Desktop                                                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                              
BuildVersion                   10.0.17134.590                                                                                                                       
CLRVersion                     4.0.30319.42000                                                                                                                      
WSManStackVersion              3.0                                                                                                                                  
PSRemotingProtocolVersion      2.3                                                                                                                                  
SerializationVersion           1.1.0.1                                                                                                                              

I have a basic script that is utilizing Invoke-DbaQuery throughout to pull data from a given SQL Server instance. This command is part of dbatools module, a rather large module by file count. The entry point for the project is a script that dot sources the previously mentioned script and also includes the import command for dbatools module.

Below code are the contents of that entry point script. The problem is the project builds successfully in VS 2019 CE but it is not packing the dbatools module with it. I have the module for Windows PowerShell installed under the PSModulePath (c:\program files\windowspowershell\modules), but have also tried the module under my profile as well (CurrentUser scope), neither of which seem to matter.

I know it is not grabbing it purely from the size of the executable, along with the errors thrown that the module is missing when running the executable. The module dbatools is a large module, zipped the file is 22MB but the executable generated is only at 197KB.

[CmdletBinding()]
param(
    [object[]]$Server,
    [int]$Port,
    [switch]$ConfigOnly
)

. "$PSScriptRoot\New-FunctionDotSourcedFile.ps1"

Import-Module -Name dbatools

$fileDate = Get-Date -Format "yyyyMMdd_HHmmss"
foreach ($s in $Server) {
    $fileName = "$(([DbaInstanceParameter]$s).ComputerName)_$(([DbaInstanceParameter]$s).InstanceName)_$fileDate.html"
    try {
        New-FunctionDotSourcedFile -server $s -port $Port -configOnly:$ConfigOnly | Out-File $fileName -Encoding utf8 -Force
    } catch {
        "Error found exeucting command: $($_.Exception)"
    }
}

The output from the build:

------ Build started: Project: assessment, Configuration: Debug Any CPU ------
        Checking license
        OutputPath is C:\git\wsmelton\tdm-assessment\assessment\bin\Debug\
        Bundling tdmassessment.ps1
        Packaging C:\Users\Shawn Melton\AppData\Local\Temp\tdmassessment.ps1
        Checking dotnet version.
        2.2.103

        Creating package project.
        Using .NET Framework version: net46
          Restoring packages for C:\Users\Shawn Melton\AppData\Local\Temp\b64b9df6dd61433694eb009ca621089c\tdmassessment.csproj...
  Generating MSBuild file C:\Users\Shawn Melton\AppData\Local\Temp\b64b9df6dd61433694eb009ca621089c\obj\tdmassessment.csproj.nuget.g.props.
  Generating MSBuild file C:\Users\Shawn Melton\AppData\Local\Temp\b64b9df6dd61433694eb009ca621089c\obj\tdmassessment.csproj.nuget.g.targets.
  Restore completed in 92.04 ms for C:\Users\Shawn Melton\AppData\Local\Temp\b64b9df6dd61433694eb009ca621089c\tdmassessment.csproj.

        Packaging C:\Users\Shawn Melton\AppData\Local\Temp\tdmassessment.ps1 -> C:\git\wsmelton\tdm-assessment\assessment\bin\Debug\\tdmassessment.exe
        Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 33.42 ms for C:\Users\Shawn Melton\AppData\Local\Temp\b64b9df6dd61433694eb009ca621089c\tdmassessment.csproj.
  tdmassessment -> C:\git\wsmelton\tdm-assessment\assessment\bin\Debug\tdmassessment.exe

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

Time Elapsed 00:00:00.98

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Comments (7)

  1. Adam Driscoll

    Are you building this via Visual Studio or Merge-Script? If from Visual Studio, can you validate that you have the setting to bundle modules enabled? I tried this with the dbatools module and it seems to be bundling fine for me.

  2. Shawn Melton reporter

    Using VS 2019 to build (RC3 but I'm getting RTM installed to see if that changes anything).

    I do have bundle modules installed...contents of my pssproj file are below.

    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <SchemaVersion>2.0</SchemaVersion>
        <ProjectGuid>6CAFC0C6-A428-4d30-A9F9-700E829FEA51</ProjectGuid>
        <OutputType>Exe</OutputType>
        <RootNamespace>MyApplication</RootNamespace>
        <AssemblyName>MyApplication</AssemblyName>
        <Name>assessment</Name>
        <PackageEntryPoint>tdmassessment.ps1</PackageEntryPoint>
        <DotNetVersion>v4.6</DotNetVersion>
        <PackageType>Console</PackageType>
        <PackageModules>True</PackageModules>
        <FileVersion>4.0.0</FileVersion>
        <ProductName>TDM Solutions Assessment</ProductName>
        <ProductVersion>4.0.0</ProductVersion>
        <Copyright>TDM Solutions 2019</Copyright>
        <PackageAsExecutable>True</PackageAsExecutable>
        <Bundle>True</Bundle>
        <HideConsoleWindow>False</HideConsoleWindow>
      </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 />
      <ItemGroup>
        <Compile Include="tdmassessment.ps1" />
        <Compile Include="New-ReportAssessment.ps1" />
      </ItemGroup>
      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
      <Target Name="Build" />
      <Import Project="$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets" Condition="Exists('$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets')" />
    </Project>
    
  3. Adam Driscoll

    Can you please try with the latest version? There was an issue with the module imports. I’m successfully bundling dbatools with 4.5.2 of poshtools.

  4. Shawn Melton reporter

    Just to verify is your success with VS 2019? I show 4.6.x version and it still doesn't seem to work for me.

    I'll try using VS Code but maybe my install of VS is messed up in some manner.

  5. Dan Rayner

    I have come searching to see if this was a known issue. Using VSCommunity 2017 within Package Modules enabled.

    In one project I import 2 modules, only one is being bundled. I copied the code to a new project and package and no modules are being bundled.

  6. Log in to comment