Dot-Net-Core
如何在沒有 App.runtimeconfig.json 的情況下建構 App?
當我在 Visual Studio 中建構
AppinRelease模式時,它會在 Release 文件夾中生成這些文件:App.exe App.dll App.runtimeconfig.json App.pdb App.deps.json App.runtimeconfig.dev.json如果我移動前 3 個文件的位置並點兩下
App.exe它開始。如果我刪除App.runtimeconfig.json它不會啟動!我只想保留在我的文件夾中
App.exe,App.dll我該怎麼做才能擺脫它App.runtimeconfig.json?編輯
以下是 的內容
App.runtimeconfig.json:{ "runtimeOptions": { "tfm": "netcoreapp3.0", "framework": { "name": "Microsoft.WindowsDesktop.App", "version": "3.0.0" } } }編輯
這是我現在
App.csproj文件中的內容PropertyGroup:<PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <PublishTrimmed>true</PublishTrimmed> <PublishReadyToRun>true</PublishReadyToRun> <PublishSingleFile>true</PublishSingleFile> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <UseWPF>true</UseWPF> </PropertyGroup>現在我在
Error ListVisual Studio 中得到了這個:Error NETSDK1047 Assets file 'C:\Users\Emon\source\repos\SocketTest\App\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers. App C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 234當我右鍵點擊項目時,我看到:建構、清理、重建等,沒有恢復!
編輯
我已經先刪除了
binandobj文件夾,然後重新排序了<PropertyGroup>以將其<RuntimeIdentifier>放在 下方<TargetFramework>,現在它可以工作了!
如您所見,
App.runtimeconfig.json包含執行時資訊和使用的 .NET Core 版本,您不能簡單地刪除它。但是您在發布應用程序時通過選擇Self-contained部署模式切換到自包含部署.NET Core 引入了修剪結果執行檔以減小大小的能力。基本上,您的項目文件中需要以下屬性
<PublishTrimmed>true</PublishTrimmed> <PublishReadyToRun>true</PublishReadyToRun> <PublishSingleFile>true</PublishSingleFile> <RuntimeIdentifier>win-x64</RuntimeIdentifier>有一篇關於單個執行檔的非常好的文章