Navigation Menu

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

Run powershell samples in clean dotnet core container #4460

Closed
Vetal-ca opened this issue Aug 2, 2017 · 5 comments
Closed

Run powershell samples in clean dotnet core container #4460

Vetal-ca opened this issue Aug 2, 2017 · 5 comments
Assignees
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered. Resolution-Duplicate The issue is a duplicate.
Milestone

Comments

@Vetal-ca
Copy link

Vetal-ca commented Aug 2, 2017

I am trying to run dot-net core app from "Host Powershell" section., https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell
So I can run .net app which require PS sessions support in minimalistic environment

Steps to reproduce

  1. Make sure you have your Docker daemon in Linux mode or just run it on Linux host
  2. Save following dockerfile locally as Dockerfile.1.1.2_ps:
FROM buildpack-deps:jessie-scm

# Install .NET CLI dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libc6 \
        libcurl3 \
        libgcc1 \
        libgssapi-krb5-2 \
        libicu52 \
        liblttng-ust0 \
        libssl1.0.0 \
        libstdc++6 \
        libunwind8 \
        libuuid1 \
        zlib1g \
        apt-transport-https	\
		git-core\
    && rm -rf /var/lib/apt/lists/*

# Install .NET Core SDK
ENV DOTNET_SDK_VERSION 1.0.4
ENV DOTNET_SDK_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-dev-debian-x64.$DOTNET_SDK_VERSION.tar.gz
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1


RUN curl -SL $DOTNET_SDK_DOWNLOAD_URL --output dotnet.tar.gz \
    && mkdir -p /usr/share/dotnet \
    && tar -zxf dotnet.tar.gz -C /usr/share/dotnet \
    && rm dotnet.tar.gz \
    && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
	&& mkdir /scripts

# Trigger the population of the local package cache
ENV NUGET_XMLDOC_MODE skip
RUN mkdir warmup \
    && cd warmup \
    && dotnet new \
    && cd .. \
    && rm -rf warmup \
&& rm -rf /tmp/NuGetScratch


#install powershell
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
	&& curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | tee /etc/apt/sources.list.d/microsoft.list \
	&& apt-get update \
	&& apt-get install -y powershell

# get powershell source 
RUN mkdir -p /projects/PowerShell && git clone https://github.com/PowerShell/PowerShell.git /projects/PowerShell

WORKDIR /projects/PowerShell/docs/host-powershell/sample-dotnet1.1

ENTRYPOINT /bin/bash

This comes from Docker hub plus code to install repo and pull Powershell repo, so there is standard and ready environment for the test

Then, run
docker build -t powershell_test -f Dockerfile.1.1.2_ps . & docker run -ti --rm powershell_test

You'll end up in sample-dotnet1.1 app directory.

Next,
dotnet restore ./MyApp/MyApp.csproj

This one succeeded and proper NuGet packckages are pulled, as it mentioned here:
#2284

NuGet Config files used:
/projects/PowerShell/docs/host-powershell/sample-dotnet1.1/NuGet.config
/projects/PowerShell/nuget.config
/root/.nuget/NuGet/NuGet.Config
Feeds used:
https://api.nuget.org/v3/index.json
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
https://powershell.myget.org/F/powershell-core/api/v3/index.json

Then, start application:
dotnet run --project ./MyApp/MyApp.csproj

Expected behavior

Application runs and produce output:


 Get-Command Write-Output                                                                                                                                                               
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Write-Output                                       3.1.0.0    Microsoft.PowerShell.Utility

Actual behavior

appBase: /projects/PowerShell/docs/host-powershell/sample-dotnet1.1/MyApp/bin/Debug/netcoreapp1.1

Evaluating 'Get-Command Write-Output' in PS Core Runspace


Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.Runspaces.RunspaceFactory' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'api-ms-win-eventing-provider-l1-1-0.dll': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at System.Management.Automation.Tracing.EtwActivity.UnsafeNativeMethods.EventActivityIdControl(ActivityControlCode controlCode, Guid& activityId)
   at System.Management.Automation.Tracing.EtwActivity.GetActivityId()
   at System.Management.Automation.Runspaces.RunspaceFactory..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at Application.Test.Logic.Start(String[] args) in /projects/PowerShell/docs/host-powershell/sample-dotnet1.1/Logic/UseRunspace.cs:line 20
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Management.Automation.PowerShellAssemblyLoadContextInitializer.InitializeAndCallEntryMethod(String basePaths, AssemblyName entryAssemblyName, String entryTypeName, String entryMethodName, Object[] args)
   at Application.Test.Program.Main(String[] args) in /projects/PowerShell/docs/host-powershell/sample-dotnet1.1/MyApp/Program.cs:line 25

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.4
OS                             Linux 4.9.36-moby #1 SMP Wed Jul 12 15:29:07 UTC 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Not being expert in .dotnet it is not quite clear what is missing here. I've tried to set different RID in project, "debian.8-x64" from "dotnet --info". Tried to publish & run. Tried to set AppBase to "/opt/microsoft/powershell/6.0.0-beta.4/"

Same error. Ok, if there some Win-only assemblies, why "powershell" executable works right in the same container? It is using the same assemblies. Or, not,

I am looking for a simple and concise answer for "mere mortals". Otherwise, I have to run a hybrid swarm with Linux and Windows node just for Powershell only. Dealing with Windows docker is pain, just pain and bugs. Even after having few successful Linux Docker deliveries

@panhsu
Copy link

panhsu commented Aug 22, 2017

Hi,
I have the same issue but the version is .netcore 2.0.

@MaximoTrinidad
Copy link

@Vetal-ca

Just to make sure. I notice you're on v6.0.0-beta.4. Have you try with PowerShell v6.0.0-beta.5?
To make sure you're getting the same issue.
:)

@iSazonov iSazonov added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Aug 22, 2017
@panhsu
Copy link

panhsu commented Aug 23, 2017

@MaximoTrinidad
My environment is PowerShell v6.0.0-beta.5.

Environment Data

 PS /app> $PSVersionTable
 Name                           Value
 ----                           -----
 PSVersion                      6.0.0-beta
 PSEdition                      Core
 GitCommitId                    v6.0.0-beta.5
 OS                             Linux 4.9.41-moby #1 SMP Fri Aug 18 07:29:56 UTC 2017
 Platform                       Unix
 PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
 PSRemotingProtocolVersion      2.3
 SerializationVersion           1.1.0.1
 WSManStackVersion              3.0

@pmsanford
Copy link

Same stack trace with the example on v6.0.0-beta.6 in .netcore 2.0 (in CentOS 7):


Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.6
OS                             Linux 3.10.0-514.26.1.el7.x86_64 #1 SMP Thu Jun 29 16:05:25 UTC 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@SteveL-MSFT SteveL-MSFT added this to the 6.0.0-HighPriority milestone Sep 12, 2017
@anmenaga anmenaga self-assigned this Sep 22, 2017
@anmenaga anmenaga added Resolution-Answered The question is answered. Resolution-Duplicate The issue is a duplicate. labels Sep 26, 2017
@anmenaga
Copy link
Contributor

I can repro on Debian 8.

Looks like this issue is because all PowerShell Core packages we published so far contain windows assemblies only.
This is blocking hosting powershell in .NET Core applications on Linux/OSX.

Essentially this is a direct result/duplicate of #3417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered. Resolution-Duplicate The issue is a duplicate.
Projects
Developer Experience/SDK
  
Awaiting triage
Development

No branches or pull requests

7 participants