On a Linux environment, create a NuGet package from a C # project and load it into another project

I'm in charge of Azure Functions kafka Extension, but recently I have a lot of pull requests, so I want to write E2E tests in languages other than C #. It has become. Most people change things just by looking at C #, but from my point of view, does it work in other languages? It's annoying to test every time, so I decided to create a mechanism.

Challenges when building the current package and loading it into a package in another language

The original Extension of this project was written in C #. So, using the created NuGet package, it feels like other languages will work, so the following is necessary.

At first glance it looks like nothing, but there are some considerations

After all, what happened was 100.100.100, well, I wouldn't update that much. I set up a version like that, and made it a simple solution to do so with the source code. There seems to be a better one.

Build C # package

Assuming dotnet is already installed, I wrote and ran the following command on WSL2. The important point is dotnet pack -o temp --include-symbols src / Microsoft.Azure.WebJobs.Extensions.Kafka / Microsoft.Azure.WebJobs.Extensions.Kafka.csproj /p:Version=100.100.100 Package Specify the version 100.100.100, execute pack, and output to the temp directory. After that, it is copied to the directory for each language. The directories for each language are configured to be packed into Docker.

#!/bin/bash

CURRENT_DIR=`pwd`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR/..

WORKING_DIR=temp
if [ -d "$WORKING_DIR" ]; then rm -rf $WORKING_DIR; fi

dotnet pack -o temp --include-symbols src/Microsoft.Azure.WebJobs.Extensions.Kafka/Microsoft.Azure.WebJobs.Extensions.Kafka.csproj /p:Version=100.100.100


PACKAGE_DIR=test/Microsoft.Azure.WebJobs.Extensions.Kafka.LangEndToEndTests/server/java8/packages
if [ -d "$PACKAGE_DIR" ]; then rm -rf $PACKAGE_DIR; fi
mkdir $PACKAGE_DIR
cp temp/* $PACKAGE_DIR

cd $CURRENT_DIR

Specifying NuGet Source

How can I get a NuGet file to read? I thought, I set Local Source and made it read. Currently, there was a command called dotnet nuget add source, so I tried using it. The old information was that I installed mono and used nuget.exe, but now it seems unnecessary.

RUN dotnet nuget add source /workspace/packages/

By the way, issuing this command updates the default NuGet.Config as follows: At first, I thought about changing the version fixing method and the priority of reading nuget source so that Local always reads first, but after all False Positive is worrisome, so fixing the version I made it.

# pwd
/root/.nuget/NuGet
# cat NuGet.Config 
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  <add key="Package source 1" value="/workspace/packages/" />
</packageSources>

Java, Python side csproj file

Because of the specification, the csproj file on the Java and Python side is only the version 100.100.100.100. This will automatically include a build of the current source code.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
	<WarningsAsErrors></WarningsAsErrors>
	<DefaultItemExcludes>**</DefaultItemExcludes>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Kafka" Version="100.100.100" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.7" />
  </ItemGroup>
  <ItemGroup>
    <None Update="confluent_cloud_cacert.pem">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Dockerfile

The final Dockerfile looks like this: Easy and messy.

FROM mcr.microsoft.com/azure-functions/java:3.0-java8-core-tools

# Copy Local File
RUN mkdir /workspace
COPY . /workspace
WORKDIR /workspace
# dotnet 

ENV LD_LIBRARY_PATH=/workspace/target/azure-functions/kafka-function-20190419163130420/bin/runtimes/linux-x64/native

RUN dotnet nuget add source /workspace/packages/

RUN mvn clean package

ENTRYPOINT [ "/usr/bin/mvn", "azure-functions:run" ]

Summary

If you're a C # master, you might come up with a better way. Please let me know if you have any. After this, I was able to start and work with the Kafka server with docker-compose, so after that, I wrote the E2E framework in C # and incorporated it into Azure DevOps, and I'm done.

Supplement 11/9/2020

I got good advice from Mr. Shibayan, so I decided to use the package reference. You don't have to make a Local Nuget anymore, so this one looks better. Since I pack it in Docker, I thought that PackageReference could not be used, but it is simple and I can make the context of docker build the project root. However, I will leave the entry because it was a good learning of the command.

image.png

extension.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
	<WarningsAsErrors></WarningsAsErrors>
	<DefaultItemExcludes>**</DefaultItemExcludes>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.7" />
  </ItemGroup>
  <ItemGroup>
    <None Update="confluent_cloud_cacert.pem">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\..\..\src\Microsoft.Azure.WebJobs.Extensions.Kafka\Microsoft.Azure.WebJobs.Extensions.Kafka.csproj" />
  </ItemGroup>
</Project>

Dockerfile

FROM mcr.microsoft.com/azure-functions/java:3.0-java8-core-tools

# Copy Local File
RUN mkdir /workspace
COPY . /workspace
WORKDIR /workspace/test/Microsoft.Azure.WebJobs.Extensions.Kafka.LangEndToEndTests/server/java8
# dotnet 

ENV LD_LIBRARY_PATH=/workspace/target/azure-functions/kafka-function-20190419163130420/bin/runtimes/linux-x64/native

RUN mvn clean package

ENTRYPOINT [ "/usr/bin/mvn", "azure-functions:run" ]

docker build -t testj8 -f test/Microsoft.Azure.WebJobs.Extensions.Kafka.LangEndToEndTests/server/java8/Dockerfile . 

Resource

Recommended Posts

On a Linux environment, create a NuGet package from a C # project and load it into another project
Create a Linux environment on Windows 10
Create a decent shell and python environment on Windows
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Install LAMP on Amazon Linux 2 and build a WordPress environment.
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
Create a VS Code + Docker development environment on a Linux VM
[MariaDB] Install MariaDB on Linux and create a DB and an operating user.
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
Prepare a machine learning project format and run it on SageMaker
Everything from building a Python environment to running it on Windows
Create a Python environment on Mac (2017/4)
Create a python environment on centos
I made a POST script to create an issue on Github and register it in the Project
Create a decision tree from 0 with Python and understand it (5. Information Entropy)
Build Linux on a Windows environment. Steps to install Laradock and migrate
Create a python environment on your Mac
Create a deb file from a python package
Create a Linux virtual machine on Windows
How to prepare an environment with different python version and package for each project with pyenv-virtualenv on Amazon Linux
Create a Django project and application in a Python virtual environment and start the server
Create a C array from a Python> Excel sheet
[Venv] Create a python virtual environment on Ubuntu
Try to create a new command on linux
Create a Python execution environment on IBM i
Create a Python virtual development environment on Windows
Steps to quickly create a deep learning environment on Mac with TensorFlow and OpenCV
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.