Add compile parameter to csc command using Visual Studio IDE

只谈情不闲聊 提交于 2019-12-10 12:55:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18849637/add-compile-parameter-to-csc-command-using-visual-studio-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!