How to set the path of appsetting.json file to DockerFile in IoT Edge Runtime Project

345 Views Asked by At

I created one IOT edge runtime custom module project on windows container. While running the solution I am facing System cannot Find the file specified. I am passing the values from appsetting.json file and while running the module the path is not getting specified.

Is it some way i can give some command to copy appsetting.json file in to container while building the image.

This is the Dockerfile i am using:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build-env
WORKDIR /app

COPY *.csproj ./
COPY appsettings.json ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1809
WORKDIR /app
COPY --from=build-env /app/out ./
ENTRYPOINT ["dotnet", "project.dll"]

This is the cs.proj file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'">
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
    <TreatSpecificWarningsAsErrors />
  </PropertyGroup>

  <ItemGroup>
    <ProjectCapability Include="AzureIoTEdgeModule" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.*" />
    <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="SasLib">
      <HintPath>lib\SasLib.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup>
    <Compile Update="Resource\Resource.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Resource.resx</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Resource\Resource.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resource.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>
</Project>
2

There are 2 best solutions below

2
On BEST ANSWER

try specifying the folder in the Windows container where the appsettings.json file should be copied

COPY appsettings.json c:/temp/
2
On

It seems that appsettings.json is not copied to the output directory. Try to add this into csproj file

 <ItemGroup>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>