How to change / replace the parameter set file when creating from the command line?

I create packages from a batch file using commands like:

msbuild ..\lib\Package.dproj /target:Build /p:config=%1 

Package settings depend on a set of options:

 <Import Project="..\optionsets\COND_Defined.optset" Condition="'$(Base)'!='' And Exists('..\optionsets\COND_Defined.optset')"/> 

This parameter defines the conditional character that many of my packages depend on. The file is as follows:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <DCC_Define>CONDITION;$(DCC_Define)</DCC_Define> </PropertyGroup> <ProjectExtensions> <Borland.Personality>Delphi.Personality.12</Borland.Personality> <Borland.ProjectType>OptionSet</Borland.ProjectType> <BorlandProject> <Delphi.Personality/> </BorlandProject> <ProjectFileVersion>12</ProjectFileVersion> </ProjectExtensions> </Project> 

Now I need two assemblies: one with a condition defined and without it. My attack vector will be a set of options file. I have some ideas on what to do:

  • write a program that modifies the parameter set file, run this before building packages
  • script with project files and changing the installation path of the options to contain an environment variable, and then have different sets of parameters in different places

But before starting to reinvent the wheel, I would like to ask how you will cope with this task. Perhaps there are already tools designed to support such a case (for example, some command line switches, something that I could configure in Delphi or the layout of a batch file).

+4
source share
2 answers

The way I approach this is to define several build configurations, and then select the appropriate /p:config=XXX at the time of build. The job works well in the IDE because you can simply double-click the assembly configuration in the project manager to activate it.

I personally use the inheritance of assembly configurations when I do this so as not to repeat myself. For example, I have an assembly configuration called Debug DCUs that inherits from the Debug configuration and simply changes the Debug DCUs parameter to True .

To explain what I mean, here is what the assembly configuration tree looks like in my project:

enter image description here

Debug DCUs are configured using this option:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <DCC_DebugDCUs>true</DCC_DebugDCUs> </PropertyGroup> <ProjectExtensions> <Borland.Personality>Delphi.Personality.12</Borland.Personality> <Borland.ProjectType>OptionSet</Borland.ProjectType> <BorlandProject> <Delphi.Personality/> </BorlandProject> <ProjectFileVersion>12</ProjectFileVersion> </ProjectExtensions> </Project> 

Now Iā€™m sure that you can do this using /p:DCC_Define=XXX , but I think that using the build configuration is cleaner so that you can be sure that what you get is the IDE is the same as what you get from the built command line.

I would not recommend a single approach to the token list. These approaches look extremely fragile to me.

+3
source

One way is to temporarily rename the .optset file; this actually disables it, since the referenced file cannot be found. You can do this from your batch file before calling msbuild. This only works for sets of options used as a link - as in your case.

Another option is to manually insert the <Import> directive in the .dproj file:

 <Import Condition="Exists('$(OptSet)')" Project="$(OptSet)"/> 

Then you can set the OptSet property from the command line, which will import the parameter:

 msbuild /t:Build /p:Config=Release /p:OptSet=myoptset.optset myproject.dproj 

Without setting the OptSet property, the OptSet set will not be imported:

 msbuild /t:Build /p:Config=Release myproject.dproj 
+1
source

Source: https://habr.com/ru/post/1383697/


All Articles