MSBuild, override property sheet on the command line - msbuild

I am searching for a way to pass a property sheet (.props file) on the command line to MSBuild. MSBuild does not seem to have a specific switch for property sheets, but does have a /property command line switch, which you can use to override individual properties within the project.
Is there some way to either provide a property sheet on the command line, or, perhaps use the /property switch to apply the property sheet?

In your project file add an Import like
<Import Project="$(CustomProps)" Condition="Exists($(CustomProps))" />
Just add it where the other imports are, or if you don't want to repeat yourself for each configuration/platform combination, add it either below the <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/> line (in which case other property sheets can override values from it) or above the <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/> line (so you can apply 'final' values with your custom property sheet).
Then on the commandline pass /p:CustomProps=/path/to/props
edit msbuild also has this functionality built-in, just figured this is sort of a duplicate of How to set PreProcessorDefinitions as a task propery for the msbuild task. Except there if you want to control where the import happens you'd have to choose between ForceImportBeforeCppTargets and ForceImportAfterCppTargets.

Related

In InstallShield, how to change the value of my Property before it is used by SQL Text Replacement?

What I want to do
In InstallShield I want to set the value of a Property before it is used by the SQL Text Replacement feature. I want the new Property value to come from an Edit control that I've added to a dialog.
What I've done so far
I have added SQL Scripts to my InstallShield project, which include placeholders for InstallShield's Text Replacement feature. I've used the Text Replacement tab to find and replace a placeholder in the SQL script with the value of a Property that I've added to the Property Manager. This works correctly, but only for the Property's default value.
Where I'm stuck
The problem is that I want the new value to come from an Edit control in my custom Dialog, but I can't find a way to do this. Text Replacement always uses the Property's default value.
What I've tried is the following InstallScript, which runs when the user clicks Next on my custom Dialog:
CtrlGetText("MyDialog", EDIT_VALUE_FROM_USER, svValueFromUser);
MsiSetProperty ( hwndDlg, "EDIT_VALUE_FROM_USER", svValueFromUser);
Where EDIT_VALUE_FROM_USER is my Property. This runs without error, but the value doesn't come through to the final SQL script.
Why isn't the new value for EDIT_VALUE_FROM_USER being used by SQL Text Replacement? How can I diagnose why it's not working? Should I be doing this in a completely different way?
This turned out to be because I wasn't using the system property ISMSI_HANDLE.
So the correct code to write a Property from an Edit control in a custom dialog is:
CtrlGetText("MyDialog", EDIT_VALUE_FROM_USER, svValueFromUser);
MsiSetProperty (ISMSI_HANDLE, "EDIT_VALUE_FROM_USER", svValueFromUser);
I'm guessing your property isn't listed in the SecureCustomPublicProperties property and is getting set back to it's default value when the installer transitions to the install execute sequence. A log file of the installation would give more data to work with.

Customize genmodel not to create plugin.xml, plugin.propeties and build.properties

I have a metamodel.ecore which I generate its Model Code from the genmodel file (Right click on metamodel.genmodel ==> Select Generate Model Code);
However, some additional files (plugin.xml, plugin.properties and build.properties) are created during code generation. Since I just need the model code for my special purpose (e.g. I don't want my current project to be converted to a plugin project), I want to prevent generating these files.
Any simple way to do that?
With the properties view opened, select the root element in your genmodel. You need to do the following changes in your genmodel:
Set All / Bundle Manifest to false. It will prevent MANIFEST.MF to be generated.
Set Model / Model Plug-in ID to empty string or use the button on the top right of the properties view named "Restore Default Value" to set it to null. It will prevent the generation of the files plugin.xml, plugin.properties and build.properties.
Set Template & Merge / Update Classpath to false. This one is optional but with your use case, you may want EMF to stop messing out with your .classpath file.

WiX: How to create file name from a property value

I have a working WiX installer that correctly writes properties to certain INI files, which works fine, but I have a need to generate the name of an INI file on the fly, from the computer name, eg.
MACHINE(xxx).INI
where xxx is my computer name.
I have tried all sorts of combinations of properties and I just can't seem to get it working. Can anyone put me right ?
This is my latest attempt that doesn't work:
<Property Id="MACHINEINI" Value="MACHINE([%COMPUTERNAME]).ini" />
...
<IniFile Id="IniPermissions"
Directory="MYDIR"
Action="addLine"
Name="[MACHINEINI]"
Section="[ComputerName]"
Key="Permissions"
Value="TEST" />
I never see the value of MACHINEINI, as the filename that gets created is actually called
[MACHINEINI]
The value it writes in is correct, so I see the contents as follows:
[xxx] Permissions=TEST
(where xxx is my machine name)
I have tried using [ComputerName], [COMPUTERNAME], [%COMPUTERNAME]
When I build the installer, I get the following error:
C:\Source\blah\BLAH.wxs(50) : warning CNDL1077 : The 'MACHINEINI' Pro
perty contains '[COMPUTERNAME]' in its value which is an illegal
reference to an other property. If this value is a string literal,
not a property reference, pl ease ignore this warning. To set a
property with the value of another property, use a CustomAction with
Property and Value attributes.
The underlying Windows Installer table doesn't support this. Note that the FileName column is of type FileName. Only the Formatted type can take a [PROPERTY].
IniFile Table
You could need a custom action to write temporary records to the IniFile table to transform the file name. The advantage versus using a custom action to literally write the INI file is that rollback would be automatically handled for you.
It's not possible to tell you how to do this exactly since I don't know what language you'd want to use to write the custom action.
A simpler approach (from the installers perspective) would be to transform the [KEY] name inside a single INI instead of writing to different INI files.

is it possible to reference .linq file in LinqPad

is it possible to call/reference functions in another query file beside MyExtensions in LinqPad?
You can call one script from another:
Another way to combine scripts is to dynamically execute one script from another. The Util.Run method does exactly that, and is useful in both interactive and command-line scenarios:
string htmlResult = Util.Run ("test.linq", QueryResultFormat.Html).AsString();
Note: If you feed Util.Run a relative path, it will resolve it relative to the 'My Queries' directory rather than the current directory. You can switch its behavior by specifying .\test.linq instead of test.linq in this example.
From:
LINQPad Command-Line and Scripting
No, this isn't possible right now.

MSBuild parse item metadata

Is there anyway to modify each item in an item group? For example, given this item:
<_CustomAreas Include="..\My.Project.*\Areas\**\*.*" Condition="'$(AppBuildFolder)' == ''" />
I want to remove the "..\My.Product.* portion. Basically we have separate project containing MVC areas, and in the Package / Deployment (MSDeploy) we want to copy them into the main project. Here's where the group is used:
<FilesForPackagingFromProject Include="%(_CustomAreas.Identity)">
<DestinationRelativePath>Areas\%(relativedir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
$(relativedir) is coming through as "..\My.Project.Plugin1\Areas**." and it ends up in the package as ZipFileRoot\My.Project.Plugin1\Areas (The .. backs out of the hardcoded Areas, and then it just creates the folder for the plugin\areas) where I'd like it to actually all end up in ZipFileRoot\Areas.
Thanks
Andy
The RegexReplace (credentials: guest/guest) task should be able to match \My.Product.* and replace with an empty string.
Something like this should work: (untested, need to verify escaping)
<RegexReplace Input="%(_CustomAreas)" Expression="\\My\.Product\..*" Replacement="" Count="-1">
<Output ItemName="_CustomAreas" TaskParameter="Output" />
</RegexReplace>
There's a little work getting the MSBuild Community Tasks up and running, but enough good stuff in there for me to find it worth the effort.
With MsBuild 4.0 You can use String methods directly in your script (or use inline tasks). With this option, you can edit your relativedir to delete the My.Project.* part .
You can see examples in this article : http://sedodream.com/2010/03/07/MSBuild40PropertyFunctionsPart1.aspx
Items in ItemGroups can have an Exclude attribute that allows you to specify items to leave out.