Visual Studio 為我的專案創建了兩個運行 exe 所需的檔案和 .exe:deps.json 和 runtimeconfig.json。我的解決方案中的第二個專案將第一個專案作為專案參考,但是這兩個檔案沒有被復制到我的第二個專案的輸出目錄中。我如何告訴 Visual Studio 它應該將這些檔案復制到第二個專案的輸出目錄中,因為參考的專案依賴于它們?
我的第一個專案的輸出目錄:
Foo.exe
Foo.deps.json
Foo.runtimeconfig.json
我的第二個專案的輸出目錄:
Bar.exe
Foo.exe
Should contain deps and runtimeconfig files, but does not
uj5u.com熱心網友回復:
我找到的解決方案是手動編輯我的 .csproj 檔案以添加以下目標:
<Target Name="AddRuntimeDependenciesToContent"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"
BeforeTargets="GetCopyToOutputDirectoryItems"
DependsOnTargets="GenerateBuildDependencyFile;
GenerateBuildRuntimeConfigurationFiles">
<ItemGroup>
<ContentWithTargetPath Include="$(ProjectDepsFilePath)"
Condition="'$(GenerateDependencyFile)' == 'true'"
CopyToOutputDirectory="PreserveNewest"
TargetPath="$(ProjectDepsFileName)" />
<ContentWithTargetPath Include="$(ProjectRuntimeConfigFilePath)"
Condition="'$(GenerateRuntimeConfigurationFiles)' == 'true'"
CopyToOutputDirectory="PreserveNewest"
TargetPath="$(ProjectRuntimeConfigFileName)" />
</ItemGroup>
</Target>
該解決方案來自https://github.com/dotnet/sdk/issues/1675#issuecomment-658779827。
該執行緒中發布了其他一些類似的解決方案,但這是唯一對我有用的解決方案。其他人要么不會始終將檔案復制到我的第二個專案,要么會導致第一個專案由于嘗試訪問尚不存在的檔案而無法構建。與這個的主要區別在于包含正確的“BeforeTargets”屬性(可能還有“DependsOnTargets”),控制在構建程序中的哪個點包含檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/484619.html