如何在 IoT Edge 运行时项目中将 appsetting.json 文件的路径设置为 DockerFile
How to set the path of appsetting.json file to DockerFile in IoT Edge Runtime Project
我在 windows 容器上创建了一个 IOT 边缘运行时自定义模块项目。
虽然 运行 我面临的解决方案是 System cannot Find the file specified。
我正在传递 appsetting.json 文件中的值,而 运行 未指定模块路径。
在构建映像时,我可以通过某种方式将 appsetting.json 文件复制到容器中吗?
这是我正在使用的 Dockerfile:
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"]
这是 cs.proj 文件
<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>
尝试在 Windows 容器中指定要复制 appsettings.json 文件的文件夹
COPY appsettings.json c:/temp/
好像appsettings.json没有复制到输出目录。
尝试将其添加到 csproj 文件中
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
我在 windows 容器上创建了一个 IOT 边缘运行时自定义模块项目。 虽然 运行 我面临的解决方案是 System cannot Find the file specified。 我正在传递 appsetting.json 文件中的值,而 运行 未指定模块路径。
在构建映像时,我可以通过某种方式将 appsetting.json 文件复制到容器中吗?
这是我正在使用的 Dockerfile:
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"]
这是 cs.proj 文件
<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>
尝试在 Windows 容器中指定要复制 appsettings.json 文件的文件夹
COPY appsettings.json c:/temp/
好像appsettings.json没有复制到输出目录。 尝试将其添加到 csproj 文件中
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>