【问题标题】:.NET core 2.1 Custom Nuget package. Problem with missing *.runtimeconfig.json file in the project where the package was installed.NET 核心 2.1 自定义 Nuget 包。安装包的项目中缺少 *.runtimeconfig.json 文件的问题
【发布时间】:2022-01-27 22:11:12
【问题描述】:

我有一个控制台应用程序项目 (.net core 2.1),它是我的“自定义包”。 包的输出是 * .dll 文件。

我已经在不同的项目上安装了自己的包。

之后

dotnet publish

我在发布文件夹中看到 *.dll(来自包)文件。

当我试图运行这个 dll 时。 我有这样的错误:

无法为 [D:\Daily\Daily*.deps.json] 使用文件流:没有这样的文件或目录 遇到致命错误。在“D:\Daily\Daily”中找不到执行应用程序所需的库“hostpolicy.dll”。无法作为独立应用程序运行。 - 应用程序作为独立应用程序运行,因为未找到“D:\Daily\Daily*.runtimeconfig.json”。 - 如果这应该是依赖于框架的应用程序,请添加“D:\Daily\Daily*.runtimeconfig.json”文件并指定适当的框架。

我花了一些时间为我的案例寻找解决方案,但我无法用我找到的可能解决方案来解决它。

当我这样做时

dotnet publish

在输出中的 Package Project 中,我看到了所有我需要的东西。

在不同项目中安装包时会出现问题。

我尝试使用

<PropertyGroup>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

我的 nuspec 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>ProjectName</id>
    <version>1.0.0.0</version>
    <title>ProjectName</title>
    <authors></authors>
    <owners></owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description></description>
    <copyright>Copyright ©  2021</copyright>
    <dependencies>
      <group targetFramework=".NETCoreApp2.1">
            some dependencies
      </group>
    </dependencies>
    <summary>ProjectName package</summary>
    <contentFiles>
      <files include="**" buildAction="None" copyToOutput="true" flatten="false" />
    </contentFiles>
  </metadata>
  <files>
    <file src="..\ProjectName\bin\Release\netcoreapp2.1\ProjectName.dll" target="lib\netcoreapp2.1\" /> 
    <file src="..\ProjectName\bin\Release\netcoreapp2.1\ProjectName.deps.json" target="lib\netcoreapp2.1\" />   
    <file src="..\ProjectName\bin\Release\netcoreapp2.1\ProjectName.runtimeconfig.json" target="lib\netcoreapp2.1\" />  
    <file src="..\ProjectName\bin\Release\netcoreapp2.1\ProjectName.runtimeconfig.dev.json" target="lib\netcoreapp2.1\" />  
  </files>
</package>

【问题讨论】:

    标签: .net .net-core nuget azure-pipelines


    【解决方案1】:

    我遇到了类似的问题。我就是这样解决的。

    我在项目生成 nuget 包中创建了一个 ProjectName.targets 文件。 Snapshot of nupkg

    使用这个 nuget 包在项目中包含这个属性

    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    

    这些链接很有帮助 Copy files from Nuget package to output directory with MsBuild in .csproj and dotnet pack command

    Automatic native and managed DLLs extracting from Nuget Package

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      相关资源
      最近更新 更多