Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

c# - Visual Studio: How to "Copy to Output Directory" without copying the folder structure?

I have a few dll files in lib folder of my project folder. In the property page of dll, I have selected "Build Action" as "Content" and "Copy to Output Directory" as "Copy always".

After build I am actually getting the dll copied but they are inside inReleaselib and not in inRelease.

Is there a way to copy dll files to inRelease (and not to inReleaselib) without writing a post-build script or resorting to nant etc?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

instead of <Content> use <ContentWithTargetPath> and specify target path, like this:

<ItemGroup>
  <ContentWithTargetPath Include="libsome_file.dat">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <TargetPath>some_file.dat</TargetPath>
  </ContentWithTargetPath>
  <None Include="libsome_file.dat" />
</ItemGroup>

Note that this entry may not be visible from Visual Studio (2012, 2015, 2017), but once manually added to the csproj, it will appear in Visual Studio. The target path will not be editable through the UI though.

Adding a <None> entry for the file will ensure that it still shows up in Visual Studio's UI.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...