New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to copy a folder to output directory and keep its root folder? #2949
Comments
The 2.0 version of the .NET SDK (visual studio 15.4+, .NET CLI 2.0.0+) has a feature that can be used for this: the <ItemGroup>
<None Include="$(SolutionDir)config\**"
CopyToOutputDirectory="PreserveNewest"
LinkBase="config\" />
</ItemGroup> |
Depending on which project type you have, the <ItemGroup>
<None Update="$(SolutionDir)config\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> If you need to do this in non-.net standard/core projects (non-"SDK" projects), you can use the <ItemGroup>
<Content Include="..\sql\**" CopyToPublishDirectory="PreserveNewest" Link="sql\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup> |
It works. Thank you! |
@dasMulli How can we specify the |
@ashishnegi if you're using this code, you can put the target folder into the |
I had to change |
@dasMulli I have following structure:
How to remove the I want this (in output directory):
|
Use the same code without <PropertyGroup>
<DefaultItemExcludes>$(DefaultItemsExclude);Components\**\*</DefaultItemExcludes>
</PropertyGroup> So there won't be conflicting items with different copy metadata. |
@dasMulli I got same result. I want to copy |
from https://stackoverflow.com/a/35065306/492 <ContentWithTargetPath Include="lib\some_file.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>some_file.dat</TargetPath>
</ContentWithTargetPath> may be worth trying with wildcards. I haven't tried it with wildcards, works fine for just one file. |
this worked for me <ContentWithTargetPath
Include="$(MSBuildThisFileDirectory)..\Files\*.*"
CopyToOutputDirectory="PreserveNewest"
TargetPath="Files\%(Filename)%(Extension)" /> |
Please note that using ContentWithTargetPath currently breaks incremental builds (As in, it will always build the project, even when nothing has changed). It seems to check the default target path for your file, instead of checking the specified TargetPath, and when the file isn't found at the default path, it concludes that the file is missing and the project must be built again. |
It seems that this is not working in razor projects. |
thanks, the content include is work for me. I am using .net core 5. please check out the below code if you need it. the startup project is CoreSystemConsole, kindly take the whole solution from here: https://github.com/KeithPoonNS/ReportEngine my startup project
the puppeteer project
|
Saved my day! Thanks, @dasMulli ! |
@dasMulli
so what happens is my bin is like this |-- file1.txt but after copying to my path, it copies all files but with no folders ! it will be like this |-- file1.txt |
Came from dotnet/project-system#3203
Following steps in @rainersigwald's post, files did have been copied to output folder, but the root folder ("config" itself) can not be copy to output path. For example:
Is there any way to keep its root folder too?
Here's the code snippet:
The text was updated successfully, but these errors were encountered: