Question

The solution consists of two projects: main.csproj and helper.csproj.

What Id'like to do is using dll which helper project will be complied into, as an embedded resource for main.dll.

For that purposes it's seems resonable to add custom compile attribute for project main: /resource: <path to dll>.

The problem is I can't find how to add this compile parameter through the Project Property.

PS Maybe someone can suggest other solution to avoid making changes in compile process.

Was it helpful?

Solution

You should be able to add the helper assembly as a resource in the main.csproj. That will make MsBuild generate the correct parameters for csc.

(MsBuild is the build engine used by .NET in general up to and including 4.x and is also used by VisualStudio.)

What you can do to set this up is:

  • Right click the Main project in the Visual Studio solution explorer and select Add existing item. Add the assembly to be embedded as a linked item from the bin folder of the helper project. (click the little arrow on the Add button in the selection dialog to access the option to add as a link).
  • In the properties for the item in the Main project, set Action to Embedded resource.

Tricky bit would be to include the correct build so that you include the debug build or the release build depending on what configuration you are building. If you need that, you can either:

  • edit main.csproj file to include the ${Configuration} variable in the path for the helper dll.
  • Add a pre-build step to the main.csproj file to copy in the assembly to a fixed place and include the file from there (the include as link bit is no longer needed then)

To make sure you always build the helper assembly when you build the main assembly I would recommend you add a project reference to the main project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top