简体   繁体   English

使用Visual Studio IDE将编译参数添加到csc命令

[英]Add compile parameter to csc command using Visual Studio IDE

The solution consists of two projects: main.csproj and helper.csproj . 该解决方案包含两个项目: main.csprojhelper.csproj

What Id'like to do is using dll which helper project will be complied into, as an embedded resource for main.dll . Id想要做的是使用将被编译到helper项目中的dll作为main.dll的嵌入式资源。

For that purposes it's seems resonable to add custom compile attribute for project main : /resource: <path to dll> . 为此,为项目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. PS也许有人可以建议其他解决方案,以避免在编译过程中进行更改。

You should be able to add the helper assembly as a resource in the main.csproj. 您应该能够将辅助程序程序集作为资源添加到main.csproj中。 That will make MsBuild generate the correct parameters for csc . 这将使MsBuild为csc生成正确的参数。

(MsBuild is the build engine used by .NET in general up to and including 4.x and is also used by VisualStudio.) (MsBuild是.NET之前(包括4.x以及更高版本)通常使用的生成引擎,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 . 右键单击Visual Studio解决方案资源管理器中的“ Main项目,然后选择“ 添加现有项” Add the assembly to be embedded as a linked item from the bin folder of the helper project. 从帮助程序项目的bin文件夹中添加要作为链接项嵌入的程序集。 (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 . Main项目中项目的属性中,将“操作”设置为“ 嵌入式资源”

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. 编辑main.csproj文件,以将${Configuration}变量包含在帮助程序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) 在main.csproj文件中添加一个预构建步骤,以将程序集复制到固定位置并从该位置包含文件(然后不再需要include as链接位)

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. 为了确保在构建主程序集时始终构建辅助程序集,建议您向主项目添加项目引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM