Issue
I have a directory which contains various csv, xml and other project related files which the project depends on. They are divided into subfolders.
I need them to be packagable with the app when I deploy it, and I also need to be able to reference their absolute locations both when debugging and when the web service is deployed.
So far I've copied the folder into the project directory and can see it in solution explorer.
I've used the following line (based on various different SO answers I've read) to reference it:
string resourcePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"GrammarDictResources");
This searches for it in a series of nested files in the debug folder, which it does not find. Firstly, Is this the correct way to reference a project folder?
I saw in other posts that one needed to set the following settings in the properties for each individual file:
If this is part of what I need to do, is there a way to perform this action in a batch action because my file directory has over 100 files and I'd rather not have to set this manually for all of them obviously.
I've tried different solutions with no success so far.
Thanks in advance.
Solution
It's possible to batch this once and for all by editing your .csproj
. If you edit it, you should see something like this:
<ItemGroup>
<Content Update="GrammarDictResources/SubFolder/YourFile.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
with one <Content>
tag per file.
However, all these can be replaced by a single one, because it's possible to use wildcards:
<ItemGroup>
<Content Update="GrammarDictResources\**\*.*" CopyToOutputDirectory="Always" />
</ItemGroup>
Note that you can also use CopyToPublishDirectory
if needed.
Answered By - Métoule Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.