gpt4 book ai didi

c# - 使用/p :PublishSingleFile=true Flag 发布时出错

转载 作者:行者123 更新时间:2023-12-04 11:31:13 27 4
gpt4 key购买 nike

我正在尝试将我的程序压缩为单个可执行文件。我正在遵循此处指定的说明:https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-core-3-0/

当我在没有/p:PublishSingleFile=true 的情况下运行我的代码时,它可以工作但不会生成单个文件(如预期)。当我添加上述标志时,我得到以下信息:

C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: System.ArgumentException: Invalid input specification: Found multiple entries with the same BundleRelativePath [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs:line 36 [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 47 [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(801,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\igorc\Work\ZConsole\ZConsole\ZConsole.csproj]

我认为这是一个环境问题,所以我创建了一个“HelloWorld”控制台应用程序,并在那里运行相同的脚本,它工作并生成一个可执行文件。

所有项目都在.NETCORE3.0下编译。

这是我的 ZConsole.csproj 的样子:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<ApplicationIcon>logo.ico</ApplicationIcon>
<StartupObject>ZConsole.ZConsole</StartupObject>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="log4net-loggly" Version="9.0.0" />
<PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="System.IO.Ports" Version="4.6.0-preview4.19114.5" />
<PackageReference Include="Topshelf" Version="4.2.1" />
<PackageReference Include="WebSocketSharp-NonPreRelease" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ZWaveDll\BasicApplication\BasicApplication_netcore.csproj" />
<ProjectReference Include="..\ZWaveDll\Utils\Utils_netcore.csproj" />
<ProjectReference Include="..\ZWaveDll\ZWaveXml\ZWaveXml_netcore.csproj" />
<ProjectReference Include="..\ZWaveDll\ZWave\ZWave_netcore.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="AssemblyInfo.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

谢谢您的帮助!

最佳答案

为了调试此问题,我发现取消选中发布选项中的单文件标志并检查输出目录中的库很有用。在我的特定情况下,我有两个程序集引用了多个相同的 COM 互操作库(IWshRuntimeLibrary 和其他)。我最终使用了引用库的 Embed Interop Types 和 Copy Local 标志,这样无论发生了什么冲突,都不再存在。

关于c# - 使用/p :PublishSingleFile=true Flag 发布时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57224961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com