OhD*_*ear 91 c# visual-studio-2010
我的项目文件夹的\ lib文件夹中有几个dll文件.在dll的属性页面中,我选择"Build Action"作为"Content"和"Copy to Output Directory"作为"Copy always".
构建之后,我实际上已经复制了dll,但是它们位于\ bin\Release\lib中,而不是在\ bin\Release中.
有没有办法将dll文件复制到\ bin\Release(而不是复制到\ bin\Release\lib)而无需编写后期构建脚本或诉诸nant等?
小智 218
而不是<Content>使用<ContentWithTargetPath>并指定目标路径,如下所示:
<ContentWithTargetPath Include="lib\some_file.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>some_file.dat</TargetPath>
</ContentWithTargetPath>
Run Code Online (Sandbox Code Playgroud)
请注意,此条目可能在Visual Studio(2012,2015,2017)中不可见,但一旦手动添加到csproj,它将显示在Visual Studio中.但是,目标路径不能通过UI进行编辑.
Ani*_*Ani 24
保留它们$(ProjectDir)\Lib,但将这些文件" 作为链接 "添加到.csproj的根目录中.现在,他们将被复制到bin\Debug(或任何其他输出文件夹),而不是在lib中.
编辑:当我正在使用的VS/MSBuild版本中没有ContentWithTargetPath时,这个答案就回来了.将这个答案留给那些可能不得不使用旧版VS的人.请停止对此发表评论,我们都知道现在有更好的方法.
son*_*nny 19
如果您的主要目的是在不使项目根目录混乱的情况下包含 DLL,另一种解决方案是将 DLL 移动到单独的共享项目并将其添加为原始项目中的引用。
(请注意,这篇文章没有直接回答这个问题,因为它不保留文件夹和项目结构,但我发现这种方法很有用,因为我能够在我的案例中重组我的项目,并且因为我想避免一些此处其他方法的缺点。)
脚步
Solution -> Add -> New Project -> Shared ProjectBuild Action: Content和Copy to Output Directory: Copy Always)References -> Add Reference -> Shared Projects设置如下所示:
添加dll文件作为项目的引用,并在引用集"Copy local"上添加为true.
在此,如果您想包含整个内容目录并且不想跟踪 Visual Studio 中的每个单独文件,那么您可以将其添加到您的项目文件中(对我来说这是一个.vcxproj文件UWP C++ 项目的一部分):
<ItemGroup>
<Content Include="Content\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
请注意,该Content目录必须与项目文件位于同一目录中,才能保留目录结构。
如果需要将Libs目录下的文件复制到VS2017根文件夹:
<ItemGroup Condition="'$(Platform)' == 'x64'">
<None Include="Libs\x64\**" Link="\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x86'">
<None Include="Libs\x86\**" Link="\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
到任何其他文件夹,包括 Libs(RecursiveDir) 文件夹
<ItemGroup Condition="'$(Platform)' == 'x86'">
<None Include="Libs\x86\**" Link="mycustomfolder\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64631 次 |
| 最近记录: |