我有一個Microsoft.NET.Sdk.Web專案,在解決方案檔案夾中我有一個Lib包含子檔案夾的檔案夾,這些子檔案夾又包含檔案,例如:
Lib
sv
myfile.dll
de
myfile.dll
我將以下內容添加到csproj:
<ItemGroup>
<Content Include="Lib\sv\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Lib\de\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
但以上是將子檔案夾及其檔案放在Lib輸出檔案夾中的檔案夾中。
我需要具備以下條件:
(OutputPath)
sv
myfile.dll
de
myfile.dll
我怎樣才能做到這一點?
uj5u.com熱心網友回復:
使用 Link如下更改輸出路徑,我還使用Visible了這樣更改不會出現在解決方案資源管理器中:
<ItemGroup>
<Content Include="Lib\sv\**">
<Link>\sv\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Lib\de\**">
<Link>\de\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
</ItemGroup>
uj5u.com熱心網友回復:
據我了解, msbuild 會將包含內容的檔案夾結構反映到輸出路徑中,并且無法更改。
我認為您唯一的選擇是手動修復輸出檔案夾以匹配您想要的。在Windows上你可以使用
move bin\Debug\net5.0\Lib\sv bin\Debug\net5.0
move bin\Debug\net5.0\Lib\de bin\Debug\net5.0
在您的解決方案中有很多方法可以自動執行此操作。一種方法是Post Build Events在project properties -> Build -> Events. 它應該將以下內容添加到您的 csproj
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="move bin\Debug\net5.0\Lib\sv bin\Debug\net5.0
move bin\Debug\net5.0\Lib\de bin\Debug\net5.0" />
</Target>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/504876.html
