0

I'm currently trying to make a library with several variable definitions I can use in different Setup Projects but without success.

I have several huge *.wxs files which are build into a library where the File/@Source should depend on project settings. The reason for that is our internal directory structur which looks like any\path\Redistributables\In-Test\X64\productA or any\path\Redistributables\RC\X86\productA so the last 2 parts of my path should change e.g. on x64 and x86 build.

Now I have several Setup Projects too which uses the same path but working in another subdirectory e.g Redistributables\In-Test\X64\AnyOtherProductB.

I dont want to pass preprocessor variables with the same values to each project because the path could change later and I would have to edit too many project settings then.

So my question: Is it possible to build something like a "Variable/property Container" with public variables/properties so I could just reference that library to use the variables defined in it for my <component><file source...>?

I've tried to achieve that with prepocessor variables before $(var.sourcedir)$(var.compilemode)$(var.platform) with no luck. These 3 are the parts I need to define once to use them in nearly all projects.

Nitro.de
  • 821
  • 10
  • 27

1 Answers1

0

Small edit here, I do this a lot where I read the question quickly and make an answer then reread the question and think my answer doesn't quite fit the question but in this case I hope it is still helpful and maybe one of the other resources referenced here will help as well.


Ah I did something like this and banged my head against the wall for a while trying to figure it out.

The problem is you can't use variables like $(var.sourceDir) in the wixlib and then change it later on when you use the lib in a project. What happens is the compiler replaces $(var.sourceDir) in your wixlib with the actual value of this variable when you build it. You can verify this by opening up your obj file and looking for a component or something that uses this directory and see that it has the value of the sourceDir variable not $(var.sourceDir).

To solve the issue we are going to use bind/wix variables (not sure of the terminology) which get evaluated at linking time.

This was the "how to" that I eventually got to which helped me a lot

So, update your variables to something like this !(bindpath.SourceDir)

<Fragment>
    <util:RegistrySearchRef Id="MSVCPPRedist_x64_12"/>

    <PackageGroup Id="MSVCPPRedist_x64_12">
        <ExePackage
            Id="MSVCPPRedist_x64_12_0_21005"
            Cache="no"
            Description="Visual C++ 2013 Redistributable needed for [WixBundleName]"
            DetectCondition="MSVCPPRedist_x64_12 OR NOT VersionNT64"
            DisplayName="Prerequisite - Visual C++ 2013 Redistributable (x64)"
            InstallCommand="/install /quiet /norestart /log vc12log.txt"
            PerMachine="yes"
            Permanent="yes"
            SourceFile="!(bindpath.PrerequisitesDir)VC++\vcredist_x64_12.exe"
            UninstallCommand="/uninstall"
            Vital="yes"/>
    </PackageGroup>
</Fragment>

And then in some props file or project file on the build machine you can include something like this:

<LinkerAdditionalOptions>-b &quot;PrerequisitesDir=$(PrerequisitesDir)\&quot;</LinkerAdditionalOptions>

Where the $(PrerequisitesDir) property was set based on a relative path in a msbuild file on the build machine like so (or use absolute path is also fine):

<!-- Directories -->      
<PrerequisitesDir>$(MSBuildThisFileDirectory)..\..\..\Installers\Prerequisites\</PrerequisitesDir>

Now when you build the linker phase will use the build time defined bindPath to find the source files.

In regards to the platform and configuration vars, I think you can use WixVariables referenced as !(wix.VariableName) but I'm not sure off the top of my head and without more experimenting myself. You can take a look at this answer here to help get more acquainted with the different types of variables. If WixVariables don't work you can just build several flavours of yoru wixlib and reference the appropriate one in your wixproj themselves by using the MSBuild properties $(configuration), ect.. in the hintpath of the wixlib file.

Community
  • 1
  • 1
Brian Sutherland
  • 4,698
  • 14
  • 16
  • Fist at all, thank you for your answer. However I don't need to to change a variable within the process. I just need a set of variables that are different in each build thats why I thought preprocessor variables would work. E.g. in x86 build I pass `platform=x86` in and on x64 `platform=64`. That way i can access my values within the project I passed the values in. The only thing here is, that I need to access these values in other projects too, which seems not to be possible. Is it possible to define wixVariables and set the values to preprocesor values? If i'm right, wixvars are public? – Nitro.de Feb 09 '17 at 07:44
  • Is the `Source` of a `` needed in compile or link phase? – Nitro.de Feb 09 '17 at 07:47
  • Since you can build the wixlib without actually having the files in their defined place I would suspect wix only looks for and packages the included files via their souce during linking time when you run light.exe. I'll try to add another answer that fleshes out what you want to do. The comment by Arkady on the question is what you need to do so that you can use $(var.configuration) and other vars in your wxs files. – Brian Sutherland Feb 09 '17 at 15:16
  • What Arkady said is the definition of preprocessor variables, I know that and I'm using them already in my projects and thats the point. Wherever I want to use lets say `$(var.Foo)` I've to declare it in the wixproj and now I've lets say 100 Projects where I need that `$(var.Foo)` I'm not gonna define that 100 times for each build. What I need, thats what my question was about, is a way to define this a single time so i can reference it in my 100 Projects where the definition should be in a library. So how can i define a variable that I can access from everywhere if the lib is referenced – Nitro.de Feb 10 '17 at 07:40
  • So I need a kind of variable type that I can use in `File/@Source` and the definition of the source should be in a library (don't has to be a preprocessor variable I guess). I dont know if I could use a `WixVariable` or `Property` or something else for that, that's part of my question. – Nitro.de Feb 10 '17 at 07:42
  • Yeah I think I'm just not properly understanding the issue you're having =[. It sounds like bindpath is what to use. You can use unnamed bind paths (-b ). You can set up your path definition to be $(SourceDir)$(Configuration)$(Platform) in a props file; just import it in the wixproj where Configuration and Platform are defined at build time. It ends up working sort of like the additional includes path. You would just need a shared named properties file on each build machine that defines the correct paths that can be imported in the wixprojs. – Brian Sutherland Feb 10 '17 at 16:59