philippgille / hello-netcoreapp

Basic .NET Core console application with additional scripts and files for building the app and creating release artifacts for a framework-dependent deployment, self-contained deployment, Docker image, Chocolatey package and AppImage
GNU General Public License v3.0
6 stars 5 forks source link

Add scripts for building via Windows Docker containers #3

Open philippgille opened 7 years ago

philippgille commented 7 years ago

Might not be possible because of the use of .NET framework classes, which might not be available in nanoserver.

philippgille commented 6 years ago

Tried to run build.ps1 interactively with docker run -it --rm -v ${pwd}:C:\app -w C:\app microsoft/dotnet:2.0-sdk, then powershell and then .\scripts\build.ps1 which lead to:

    Directory: C:\app\artifacts

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/8/2017  12:04 PM                hello-netcoreapp_v0.1.0_netcoreapp2.0
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\hello-netcoreapp.dll
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\hello-netcoreapp.dll" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\hello-netcoreapp.pdb" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
Add-Type : Cannot find path 'C:\app\System.IO.Compression.FileSystem.dll' because it does not exist.
At C:\app\scripts\build.ps1:47 char:5
+     Add-Type -Assembly "System.IO.Compression.FileSystem"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\app\System.I....FileSystem.dll:String) [Add-Type], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.AddTypeCommand

Then tried to run automatically with docker run --rm -v ${pwd}:C:\app -w C:\app microsoft/dotnet:2.0-sdk powershell .\scripts\build.ps1, which lead to a different output:

    Directory: C:\app\artifacts

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/8/2017  12:08 PM                hello-netcoreapp_v0.1.0_netcor
                                                 eapp2.0
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_netcoreapp2.0\
Add-Type : Cannot find path 'C:\app\System.IO.Compression.FileSystem.dll'
because it does not exist.
At C:\app\scripts\build.ps1:47 char:5
+     Add-Type -Assembly "System.IO.Compression.FileSystem"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\app\System.I....FileSystem.d
   ll:String) [Add-Type], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.AddTy
   peCommand

The first one has errors when copying the *.dll from the obj to the bin path and with the System.IO.Compression.FileSystem assembly, the second one only with the assembly.

The PowerShell version in nanoserver is not the full PowerShell, but PowerShell Core. See https://docs.microsoft.com/en-us/windows-server/get-started/powershell-on-nano-server.

It looks like the Add-Type -Assembly in the build script is just looking in the wrong place, but this is probably because the assembly is not available globally, so as an alternative it's looking for the dll in the current working directory and that's where the error message comes from.

philippgille commented 6 years ago

The following brought me one step further (interactively in the Docker container):

PS C:\app> cd .\src
PS C:\app> dotnet add package 40-System.IO.Compression.FileSystem --version 1.0.0.2
PS C:\app> Add-Type -Assembly "C:\Users\ContainerAdministrator\.nuget\packages\40-system.io.compression.filesystem\1.0.0.2\lib\net40-client\System.IO.Compression.FileSystem.dll"

This actually adds the reference to the project, which we don't want, but that can be improved later. Install-Package doesn't work, probably because NuGet isn't set up as source for the package manager (which could probably be done easily).

Now the error when running .\scripts\build.ps1 (from the repo's root directory again) is:

    Directory: C:\app\artifacts

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/8/2017  12:45 PM                hello-netcoreapp_v0.1.0_netcoreapp2.0
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_netcoreapp2.0\
d-----        10/8/2017  12:45 PM                hello-netcoreapp_v0.1.0_net461
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:45 PM                hello-netcoreapp_v0.1.0_net451
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:45 PM                hello-netcoreapp_v0.1.0_win-x64
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\win-x64\hello-netcoreapp.dll
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\win-x64\hello-netcoreapp.dll" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\win-x64\hello-netcoreapp.pdb" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:45 PM                hello-netcoreapp_v0.1.0_linux-x64
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\linux-x64\hello-netcoreapp.dll
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\linux-x64\hello-netcoreapp.dll" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\linux-x64\hello-netcoreapp.pdb" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:45 PM                hello-netcoreapp_v0.1.0_linux-arm
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\linux-arm\hello-netcoreapp.dll
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\linux-arm\hello-netcoreapp.dll" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\linux-arm\hello-netcoreapp.pdb" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:46 PM                hello-netcoreapp_v0.1.0_osx-x64
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\osx-x64\hello-netcoreapp.dll
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\osx-x64\hello-netcoreapp.dll" because it was not found. [C:\app\src\hello-netcoreapp.csproj]
C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(137,5): error MSB3030: Could not copy the file "obj\release\netcoreapp2.0\osx-x64\hello-netcoreapp.pdb" because it was not found. [C:\app\src\hello-netcoreapp.csproj]

For some reason, after deleting all existing .\artifacts\* files, building the netcoreapp2.0 FDD and all SCDs worked fine, and only the net461 and net451 FDDs failed:

    Directory: C:\app\artifacts

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_netcoreapp2.0
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_netcoreapp2.0\
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_net461
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_net451
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\app\src\hello-netcoreapp.csproj]
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_win-x64
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\win-x64\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_win-x64\
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_linux-x64
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\linux-x64\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_linux-x64\
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_linux-arm
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\linux-arm\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_linux-arm\
d-----        10/8/2017  12:52 PM                hello-netcoreapp_v0.1.0_osx-x64
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  hello-netcoreapp -> C:\app\src\bin\release\netcoreapp2.0\osx-x64\hello-netcoreapp.dll
  hello-netcoreapp -> C:\app\artifacts\hello-netcoreapp_v0.1.0_osx-x64\

Adding a targeting pack is part of #38 (whose goal it is to build the net461 and net451 FDDs in a Linux container as well), so let's wait for that issue to be resolved first, before continuing here.

philippgille commented 6 years ago

Blocked by #38

philippgille commented 6 years ago

Have a look at the implementation for #46, some of that might be useful here.