Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行由dotnet publish发布的程序集时找不到依赖项_C#_.net Core - Fatal编程技术网

C# 执行由dotnet publish发布的程序集时找不到依赖项

C# 执行由dotnet publish发布的程序集时找不到依赖项,c#,.net-core,C#,.net Core,我编写了一个.NETCore2.0控制台应用程序。使用dotnet Publish发布,但在执行过程中出现错误: 运行失败 编译项目 dotnet publish src\Bucket.CLI\Bucket.CLI.csproj-c发行版--自包含的false 执行程序 bin\Release\netcoreapp2.0\publish dotnet Bucket.CLI.dll 提示错误: 错误: 应用程序依赖项清单(Bucket.CLI.dep)中指定的程序集 s、 找不到json文

我编写了一个.NETCore2.0控制台应用程序。使用
dotnet Publish
发布,但在执行过程中出现错误:

运行失败 编译项目

dotnet publish src\Bucket.CLI\Bucket.CLI.csproj-c发行版--自包含的false
执行程序

  • bin\Release\netcoreapp2.0\publish
dotnet Bucket.CLI.dll
提示错误:

错误:
应用程序依赖项清单(Bucket.CLI.dep)中指定的程序集
s、 找不到json文件:
包:“System.Text.Encoding.CodePages”,版本:“4.5.1”
路径:“runtimes/win/lib/netcoreapp2.0/System.Text.Encoding.CodePages.dll”
成功运行 但是,如果我指定一个
--运行时
,则不会发生错误:

编译项目

dotnet publish src\Bucket.CLI\Bucket.CLI.csproj-c发行版--自包含的false-r win-x64
执行程序

  • bin\Release\netcoreapp2.0\win-x64\publish
dotnet Bucket.CLI.dll
程序运行良好

这会导致什么呢


如果我将post添加到add:
Bucket.CLI.runtimeconfig.dev.json
,那么程序可以成功运行。但这是行不通的。还有别的办法吗

{
  "runtimeOptions": {
    "additionalProbingPaths": [
      "C:\\Users\\menghanyu\\.dotnet\\store\\|arch|\\|tfm|",
      "C:\\Users\\menghanyu\\.nuget\\packages",
      "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
    ]
  }
}
当我添加
--runtime
进行编译时,没有
Bucket.CLI.runtimeconfig.dev.json
程序也在成功运行

我很困惑,为什么会这样


csproj文件
  • src/Bucket/Bucket.csproj(.net standard2.0)
  • src/Directory.Build.props(公共)

您可以共享csproj文件吗?@MartinUllrich我已经重新编辑了内容并附加了使用的csproj。参考相关github问题-我得到了与针对netcoreapp3.1的项目完全相同的错误,以及相同的输出、相同版本的代码页和netcoreapp2.0。我的项目存储库中没有代码页的引用。也就是说,我的构建工作在一个单独的
dotnet构建
步骤上,然后
dotnet发布
使用
——无构建
。如果我只是运行publish并让它在同一个命令中生成,那么问题就消失了。
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AssemblyVersion>0.0.0.0</AssemblyVersion>
    <FileVersion>0.3.7250.21600</FileVersion>
    <Version>0.3.0+source</Version>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.6.0-preview7.19362.9" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.11" />
    <PackageReference Include="System.IO.Compression" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
      <EmbeddedResource Include="Assets\Schema\**">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="Assets\Signature\**">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </EmbeddedResource>
  </ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <StartupObject>Bucket.CLI.Program</StartupObject>
    <Version>0.3.0+source</Version>
    <AssemblyVersion>0.0.0.0</AssemblyVersion>
    <FileVersion>0.3.7250.21600</FileVersion>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Bucket\Bucket.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="bucket">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="bucket.bat">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>
<Project>
  <PropertyGroup>
    <IsTestProject>$(MSBuildProjectName.Contains('Tests'))</IsTestProject>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsAsErrors />
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
    <Reference Include="GameBox.Console">
        <HintPath>..\..\lib\GameBox.Console\GameBox.Console.dll</HintPath>
    </Reference>
    <Reference Include="GameBox.Semver">
        <HintPath>..\..\lib\GameBox.Semver\GameBox.Semver.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" Version="3.1.0-beta3-final" />
    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="all" Version="2.9.2" />
    <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="SonarAnalyzer.CSharp" Version="7.14.0.8411">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <Choose>
    <When Condition="'$(IsTestProject)' == 'true'">
      <PropertyGroup>
        <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)analysis.test.ruleset</CodeAnalysisRuleSet>
      </PropertyGroup>

      <ItemGroup>
        <PackageReference Include="coverlet.msbuild" Version="2.6.1">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
        <PackageReference Include="Moq" Version="4.11.0-rc1" />
        <PackageReference Include="MSTest.TestAdapter" Version="2.0.0-beta4" />
        <PackageReference Include="MSTest.TestFramework" Version="2.0.0-beta4" />
      </ItemGroup>
    </When>
    <Otherwise>
      <PropertyGroup>
        <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)analysis.ruleset</CodeAnalysisRuleSet>
      </PropertyGroup>
    </Otherwise>
  </Choose>
</Project>