1

I'm using Visual Studio Community 2017 and my projects are written in C#.

Project setup:

Let's assume I have a class library project, called (A).

And I have another project that creates an executable, called (B).

In Visual Studio (B) has a reference on (A). Library (A)'s dll gets automatically copied over to the output directory of (B).


Problem:

The class library (A) needs some additional files, that are created while the project compiles.

(So I can't just add them to visual studio as resources and set them up as "copy if newer")

Project (A) has a pre-build command set up to create these resources. This command invokes a content processor to process a bunch of library related assets. I want these processed asset files to be linked to my library (A). So if another project references (A), I want these asset files to get copied over as well.

Copying the processed assets into the output directory of (A) apparently did not do the trick.

My actual question is: How do I tell Visual Studio to also copy the compile-time created files of project (A) into project (B)'s output directory?

Community
  • 1
  • 1
  • maybe create nuget package? – Alexan Feb 09 '20 at 01:58
  • Thats actually quite a good idea. I'm currently looking into it. If I create a nuget package of my class library (A) and reference that package in project (B), will (B) automatically be updated when I make changes to the nuget package? – AquilaAbriel Feb 09 '20 at 02:08
  • no, you need to update it in nuget package manager – Alexan Feb 09 '20 at 02:18

1 Answers1

2

I know it looks kinda stupid to answer my own question like an hour later but... Maybe someone else might find my solution useful:

As Alexan commented on my initial question, creating a custom nuget package and hosting it locally might be a relatively easy and elegant solution. I will definetly try that out as well. I think by following this blog post I might be able to achieve this: https://www.wiliam.com.au/wiliam-blog/creating-a-nuget-package

But, I also figured out another way, which relates to this question: How do I “Add Existing Item” an entire directory structure in Visual Studio? As it turns out, by manually editing the csproj file of my class library, I can define a directory to include as linked content. All the files within this directory get fetched automatically when the projects gets compiled. All the files within this directory are copied over to project (B) automatically. (My compile-time generated assets as well)

<ItemGroup>
<Content Include="$([System.IO.Directory]::GetFiles(&quot;PathToFolderToInclude&quot;,&quot;*&quot;,SearchOption.AllDirectories))">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

So, I would call this topic solved. If somebody else has another idea how to solve this problem I would like to know.