2

I have two modules which build and deploy just fine. But they both have shared code which I want to pull to a separate "Shared" project. The modules have a reference to the shared project and everything seems to work.

But when I want to build the docker image I get this trace:

PROCESSING DOCKER FILE: ./Dockerfile
    PUBLISHING MODULE: modules/Valid.PrivacyCrawler.Crawlers
    Microsoft (R) Build Engine version 15.5.179.9764 for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.
    BUILDING DOCKER IMAGE: privacycrawler.azurecr.io/valid.privacycrawler.crawlers:0.0.12-amd64
    Traceback (most recent call last):
      File "/usr/local/bin/iotedgedev", line 11, in <module>
        sys.exit(main())
      File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
        return self.main(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
        rv = self.invoke(ctx)
      File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
        return f(get_current_context(), *args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/iotedgedev/cli.py", line 132, in push
        ctx.invoke(modules, push=push, deploy=deploy, no_build=no_build)
      File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/iotedgedev/cli.py", line 454, in modules
        mod.push(no_build=no_build)
      File "/usr/local/lib/python2.7/dist-packages/iotedgedev/modules.py", line 22, in push
        self.build_push(no_build=no_build)
      File "/usr/local/lib/python2.7/dist-packages/iotedgedev/modules.py", line 77, in build_push
        build_result = self.dock.docker_client.images.build(tag=image_destination_name, path=".", dockerfile=docker_file_name, buildargs={"EXE_DIR": mod_proc.exe_dir})
      File "/usr/local/lib/python2.7/dist-packages/docker/models/images.py", line 183, in build
        raise BuildError(chunk['error'], result_stream)
    docker.errors.BuildError: The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

When I duplicate the code and don't use the shared project it just builds the modules without a problem.

Is having a shared project, which is .NET core just like the modules, not supported?

I can use NuGet packages (like Newtonsoft.JSON) without a problem.

Raduan Santos
  • 1,023
  • 1
  • 21
  • 45
Stephan Bisschop
  • 198
  • 1
  • 12

3 Answers3

0

Yes, as far as i know, it does not support shared project for edge module. But you can create a library project,build the project, and then add the dll as reference to the module project.It can work around. You can post a feedback here for this requirement. enter image description here

Michael Xu
  • 4,382
  • 1
  • 8
  • 16
0

Also posted this as an issue on the IoTEdgeDev GitHub. Seems that with the full release of IoT Edge some things broke and they will fix the shared projects bug with the full release of IoT Edge Dev.

@Michael Xu, I've already tried that and I get the same exception. Also tried making a NuGet package out of my project and adding it that way, no luck.

https://github.com/Azure/iotedgedev/issues/207

Stephan Bisschop
  • 198
  • 1
  • 12
0

We actually manage to use a shared project, but the tricky thing is to modify your Dockerfile to include all referenced projects. This has to be done manually. You have to add a line similar to this one in Dockerfile:

COPY ReferencedProjectFolder/ReferencedProject.csproj ReferencedProjectFolder/

Then, however, you cannot use the VS Build, because it passes a context limited to the folder of the module being built. You have to write your own docker build command and build the modules via Powershell. The command could be copied form VS Build output. But the context parameter of the build command should also be changed to use the parent directory. An example:

cd <module_folder>
docker build --rm -f $dockerfileName -t $imageNameTagged $buildContext

The $buildContext should be a path to the parent dir where the module and all its referenced projects are subfolders, otherwise the above COPY command will fail, because it does not "see" the referenced project folder.

In this way we have implemented all basic layers: Data, Business, Common, etc. Furthermore, we manage to implement an inheritance mechanism where e.g. the Base class is added as a separate module, but not actually defined in the IoT Edge deployment json.

Hope this helps a little.

Vladislav
  • 2,772
  • 1
  • 23
  • 42