I am using WixSharp v1.9.2.0 to build an MSI file, but when I call the project.BuildMsi()
method, WixSharp creates temporary files in the %Temp%
folder of Windows. However, my project is quite large, and soon my C drive is full, causing the MSI creation to fail.
Is there a way to change the folder that WixSharp uses for its temporary files? If so, how can I do that?
Wix# using standard Path.GetTempPath
& Path.GetTempFileName
methods to get location for temp files.
Per the documentation these methods checks for the existence of environment variables in the following order and returns the first path found:
TMP
environment variable.TEMP
environment variable.USERPROFILE
environment variable.So, you can change the temp folder location by changing TMP
environment variable for the project during the build and msi authoring.
To do so you need to add the following into your wix# csproj (tested for sdk-style project)
<UsingTask TaskName="SetEnvironmentVariableTask"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Name ParameterType="System.String" Required="true" />
<Value ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Environment.SetEnvironmentVariable(Name, Value);
]]>
</Code>
</Task>
</UsingTask>
<Target Name="SampleTarget" BeforeTargets="MSIAuthoring">
<SetEnvironmentVariableTask Name="TMP" Value="D:\temp\" />
</Target>
Here we can see:
SetEnvironmentVariableTask
inline task which executes the C# code specified inside a Code
nodeSampleTarget
target which is called before wix# MSIAuthoring
target and calls SetEnvironmentVariableTask
to set %tmp%
to the D:\temp\
.Notes:
%temp%
folder before authoring msi. You can do this manually or add appropriate code into the Main
before any wix# actions.MSIAuthoring
(source) which is subject to change on the wix#-side. So, you need to control this aspect on every wix# update and update your code accordingly.