-1

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>
Arshit Singh
  • 103
  • 4
  • 14

2 Answers2

0

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

COPY appsettings.json c:/temp/
Alex alex
  • 116
  • 1
  • 1
  • 7
  • Should i include it in dockerfile? – Arshit Singh Nov 26 '20 at 12:08
  • Here is the syntax of the command from the official site `COPY test.txt /absoluteDir/` maybe the dot before the directory does not need to be specified? and `The example below uses a relative path, and adds “test.txt” to /relativeDir/: COPY test.txt relativeDir/ Whereas this example uses an absolute path, and adds “test.txt” to /absoluteDir/ COPY test.txt /absoluteDir/` – Alex alex Nov 27 '20 at 23:11
0

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>
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116