Skip to content

Commit

Permalink
- VSTemplates update. Added warning message about project.GUID. Tri…
Browse files Browse the repository at this point in the history
…ggered by #1597
  • Loading branch information
oleg-shilo committed Jul 20, 2024
1 parent 49e2ccb commit dc30c8f
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

// project.AddUIProject("$safeprojectname$.UI"); // name of the 'Custom UI Library' project in the solution

#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

project.Load += (e) =>
{
Native.MessageBox("OnLoad", "WixSharp - .NET8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static void Main()
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));

#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

project.ManagedUI = ManagedUI.Empty; //no standard UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static void Main()
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));

#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

project.ManagedUI = ManagedUI.Empty; //no standard UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static void Main()
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));

#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

//custom set of standard UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ static void Main()
var project = new ManagedProject("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));


#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

//custom set of standard UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static void Main()
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));

#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

//project.ManagedUI = ManagedUI.Empty; //no standard UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ static void Main()
var project = new ManagedProject("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));


#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

//project.ManagedUI = ManagedUI.Empty; //no standard UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static void Main()
var project = new ManagedProject("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));


#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

// project.ManagedUI = ManagedUI.DefaultWpf; // all stock UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static void Main()
var project = new ManagedProject("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));


#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

// project.ManagedUI = ManagedUI.DefaultWpf; // all stock UI dialogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static void Main()
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));

#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");
//project.SourceBaseDir = "<input dir path>";
//project.OutDir = "<output dir path>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ static void Main()
var project = new Project("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("Program.cs")));


#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");
//project.SourceBaseDir = "<input dir path>";
//project.OutDir = "<output dir path>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static void Main()
new MsiPackage(productMsi) { DisplayInternalUI = true });

bootstrapper.Version = new Version("1.0.0.0");
#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
bootstrapper.UpgradeCode = new Guid("6f330b47-2577-43ad-9095-1861bb25844b");
// bootstrapper.Application = new SilentBootstrapperApplication();
// bootstrapper.PreserveTempFiles = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static void Main()
new MsiPackage(productMsi) { DisplayInternalUI = true });

bootstrapper.Version = new Version("1.0.0.0");
#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
bootstrapper.UpgradeCode = new Guid("6f330b47-2577-43ad-9095-1861bb25844b");
// bootstrapper.PreserveTempFiles = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static void Main()
});

bootstrapper.Version = new Version("1.0.0.0");
#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
bootstrapper.UpgradeCode = new Guid("6f330b47-2577-43ad-9095-1861bb25844b");

bootstrapper.Application = new ManagedBootstrapperApplication("%this%");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static void Main()
});

bootstrapper.Version = new Version("1.0.0.0");
#warning "DON'T FORGET to replace this with a freshly generated GUID and remove this `#warning` statement."
bootstrapper.UpgradeCode = new Guid("6f330b47-2577-43ad-9095-1861bb25844b");

bootstrapper.Application = new ManagedBootstrapperApplication("%this%");
Expand Down
6 changes: 3 additions & 3 deletions Source/src/WixSharp.Samples/Wix# Samples/Features/setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//css_ref Wix_bin\WixToolset.Dtf.WindowsInstaller.dll;
//css_ref System.Core.dll;
using System;
using System.Linq;

// using System.IO;
using System.Windows.Forms;
using WixSharp;
Expand Down Expand Up @@ -40,8 +42,6 @@ static public void Main()
project.UI = WUI.WixUI_FeatureTree;

project.DefaultFeature = binaries; //this line is optional
project.UnelevateAfterInstallEvent();


project.DefaultDeferredProperties += ",FEATURE_INSTALL_PATH2";
project.AfterInstall += (SetupEventArgs e) =>
Expand All @@ -56,7 +56,7 @@ static public void Main()
}
};


project.AddCustomActionRefAssembliesOf(typeof(Script));

// project.PreserveTempFiles = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static public void Main()
};

// project.UnelevateAfterInstallEvent(); // just for demo purposes
Compiler.AutoGeneration.AddManagedCustomActionDependencies = true;

project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
// project.PreserveTempFiles = true;
Expand Down
15 changes: 2 additions & 13 deletions Source/src/WixSharp/CommonTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,19 +1100,7 @@ static public void Wxl3_to_Wxl4(this string source, string destination)
/// <param name="type">The Type from the managed CA.</param>
public static void AddCustomActionRefAssembliesOf(this Project project, Type type)
{
var dependencies = type.Assembly
.GetReferencedAssemblies()
.Where(x => !x.Name.StartsWith("System"))
.Select(x =>
{
try
{
return System.Reflection.Assembly.Load(x).Location;
}
catch { return null; }
})
.Where(x => x.IsNotEmpty() && !x.StartsWith(Environment.SpecialFolder.Windows.GetPath(), true))
.ToArray();
var dependencies = type.Assembly.GetRefAssemblies();

project.DefaultRefAssemblies.AddRange(dependencies);
}
Expand Down Expand Up @@ -2020,6 +2008,7 @@ public static ManagedProject MapAsDeferredProperty(this ManagedProject project,
/// </summary>
/// <param name="project">The project.</param>
/// <returns></returns>
[Obsolete("This method is obsolete. Use `project.AfterInstallEventExecution = EventExecution.MsiSessionScopeImmediate;` instead")]
public static ManagedProject UnelevateAfterInstallEvent(this ManagedProject project)
{
project.WixSourceGenerated +=
Expand Down
47 changes: 47 additions & 0 deletions Source/src/WixSharp/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ THE SOFTWARE.
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using WixSharp.Bootstrapper;
Expand Down Expand Up @@ -130,6 +131,16 @@ internal object WxsGenerationSynchObject
/// </summary>
public bool ForceComponentIdUniqueness = false;

/// <summary>
/// The option for adding managed custom action dependencies automatically.
/// <p> This option is a convenient way to add all the dependencies automatically setting them manually.
/// The compiler analyzes the CA assembly dependencies and adds them to the CA binary that is packaged
/// with "WixToolset.Dtf.MakeSfxCA.exe". </p>
/// <p>Note, this method may unnecessarily increase the size of the msi as not all CA dependency assemblies
/// may be required at runtime (during the installation).</p>
/// </summary>
public bool AddManagedCustomActionDependencies = false;

/// <summary>
/// Remove media if no files are included
/// </summary>
Expand Down Expand Up @@ -3319,6 +3330,42 @@ static void PackageManagedAsm(string asm, string nativeDll, string[] refAssembli

var requiredAsms = new List<string>(refAssemblies);


if (Compiler.AutoGeneration.AddManagedCustomActionDependencies)
{
#if !NETCORE
string[] dependencies = (string[])Utils.ExecuteInTempDomain<AsmReflector>(asmReflector => asmReflector.GetRefAssemblies(asmFile));

// dependencies are loaded in the temp domain and their location may not be original (preferred). IE in the temp folder
// so we need to resolve them to the original locations if possible
var localAssemblies = AppDomain.CurrentDomain.GetAssemblies()
.Select(x =>
{
try
{
return x.Location;
}
catch
{
return null;
}
})
.Where(x => x.IsNotEmpty());

for (int i = 0; i < dependencies.Length; i++)
{
var localAsmPath = localAssemblies.Where(x => x.PathGetFileName() == dependencies[i].PathGetFileName()).FirstOrDefault();
if (localAsmPath != null)
dependencies[i] = localAsmPath;
}

dependencies.Where(x => !requiredAsms.Contains(x))
.ForEach(x => requiredAsms.Add(x));
#else
throw new NotImplementedException($"The option {nameof(Compiler.AutoGeneration.AddManagedCustomActionDependencies)} is not implemented on .NET Core");
#endif
}

if (refAssemblies.Any(x => x.PathGetFileName() == "WixSharp.UI.dll") &&
!refAssemblies.Any(x => x.PathGetFileName() == "WixToolset.Mba.Core.dll"))
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/WixSharp/ProjectValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public bool ValidateCustomBaAssembly(string assembly)
return valid;
}

public string[] GetRefAssemblies(string file)
{
return ReflectionExtensions.GetRefAssembliesOf(file);
}

public void ValidateCAAssembly(string file, string dtfAsm)
{
// `ValidateCAAssemblyImpl` will load assembly from `file` for validation. Though for this to happen
Expand Down
28 changes: 28 additions & 0 deletions Source/src/WixSharp/Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ public static Session Create()

static class ReflectionExtensions
{
public static string[] GetRefAssembliesOf(string assembly)
{
try
{
return GetRefAssemblies(System.Reflection.Assembly.LoadFrom(assembly));
}
catch { return new string[0]; }
}

public static string[] GetRefAssemblies(this System.Reflection.Assembly assembly)
{
var dependencies = assembly
.GetReferencedAssemblies()
.Where(x => !x.Name.StartsWith("System"))
.Select(x =>
{
try
{
return System.Reflection.Assembly.ReflectionOnlyLoad(x.FullName).Location;
}
catch { return null; }
})
.Where(x => x.IsNotEmpty() && !x.StartsWith(Environment.SpecialFolder.Windows.GetPath(), true))
.ToArray();

return dependencies;
}

public static object Call(this MethodInfo method, params object[] args)
{
object instance = method.IsStatic ? null : Activator.CreateInstance(method.DeclaringType);
Expand Down

0 comments on commit dc30c8f

Please sign in to comment.