Car*_*ñoz 3 winforms .net-core .net-core-3.0
我有一个 Winforms .NET Core 3 应用程序,我想将其发布为独立的单文件部署
这是相关.csproj
文件
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
<ItemGroup>
<!--PackageReferences-->
</ItemGroup>
<ItemGroup>
<!--ProjectReferences-->
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我正在使用<RuntimeIdentifier>win-x64</RuntimeIdentifier>
它,因此它为 Windows x64 生成一个自包含部署,<PublishSingleFile>true</PublishSingleFile>
因此所有内容都嵌入到.exe
文件中。
通过运行发布时:
dotnet publish -c Release
Run Code Online (Sandbox Code Playgroud)
我得到的.exe
和.pdb
在文件bin\Release\netcoreapp3.0\win-x64\publish
- MyApp.exe
- MyApp.pdb
Run Code Online (Sandbox Code Playgroud)
我需要在.csproj
文件中更改什么才能获得MyApp.dll.config
或MyApp.exe.config
旁边正确的内容,.exe
以便应用程序实际从中读取配置而不是其嵌入的配置App.Config
?
我试过添加这个
<ItemGroup>
<Content Update="*.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
正如此链接Single-file Publish - Build System Interface所暗示的那样,但它仍然只生成两个文件。
你的问题帮我解决了这个问题,谢谢。希望这也适用于您。
我的 .csproj 看起来像
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Content Include="*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
刚刚用 .config 文件做了一些进一步的测试
<ItemGroup>
<None Update="*.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
这对我有用,上面的其他配置。
归档时间: |
|
查看次数: |
2590 次 |
最近记录: |