public static NetVersion FromAssembly(string assemblyPath) { var ret = new NetVersion() { DisplayVersion = "0.0.0", RealVersion = new Version(0, 0, 0) }; AppDomain sandbox = null; //create a discardable AppDomain try { sandbox = AppDomain.CreateDomain($"sandbox_{Guid.NewGuid()}", null, new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, }); var handle = Activator.CreateInstance(sandbox, typeof(ReferenceLoader).Assembly.FullName, typeof(ReferenceLoader).FullName, false, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, CultureInfo.CurrentCulture, new object[0]); var loader = (ReferenceLoader)handle.Unwrap(); //This operation is executed in the new AppDomain var frameworkName = loader.LoadReference(assemblyPath); if (frameworkName != null) { var displayVersion = Regex.Match(frameworkName, @"(\d+\.\d+(?:\.\d+(?:\.\d+)?)?)").Value; Console.WriteLine($"Assembly '{assemblyPath}' is compiled against .NET version '{displayVersion}'"); var versionArray = displayVersion.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse) .Merge(Enumerable.Repeat(0, 4), Math.Max).ToArray(); ret = new NetVersion() { DisplayVersion = displayVersion, RealVersion = new Version(versionArray[0], versionArray[1], versionArray[2], versionArray[3]) }; } } catch (Exception exception) { Console.WriteLine( $"Exception occured while processing assembly '{assemblyPath}' - details: '{exception.Message}'"); } finally { if (sandbox != null) { AppDomain.Unload(sandbox); } } return(ret); }
public static Prerequisite GetPrerequisite(NetVersion netVersion) { Console.WriteLine($"Getting .NET prerequisite for .NET version {netVersion.DisplayVersion}"); var errorMessage = $"requires .NET Framework {netVersion.DisplayVersion} or higher."; if (netVersion.RealVersion <= new Version(4, 0)) { return new Prerequisite() { ErrorMessage = errorMessage, WixPrerequisite = "NETFRAMEWORK40FULL='#1'" } } ; return(new Prerequisite() { ErrorMessage = errorMessage, WixPrerequisite = $"WIX_IS_NETFRAMEWORK_{netVersion.DisplayVersion.Replace(".",string.Empty)}_OR_LATER_INSTALLED" }); }
public static string GetPackegeRef(NetVersion netVersion) { return($"NetFx{netVersion.DisplayVersion.Replace(".", string.Empty)}Web"); }
public string BuildMsi() { var baseBinPath = $@"..\Computator.NET\{SharedProperties.OutDir}\v{_dottedNetVersion}"; var binariesPath = System.IO.Path.Combine(baseBinPath, @"*.*"); Console.WriteLine($"Analyzing binaries from path '{binariesPath}'"); var assemblies = System.IO.Directory.GetFiles(baseBinPath).Where(f => f.EndsWith(".dll")).ToList(); //assemblies.AddRange(System.IO.Directory.GetFiles(binariesPath.Replace("*.*", "*.exe"))); foreach (var assembly in assemblies) { var version = NetVersion.FromAssembly(assembly); if (version.RealVersion > CurrentHighestVersion.RealVersion) { CurrentHighestVersion = version; } } Console.WriteLine($"Highest .NET version among included assemblies is '{CurrentHighestVersion.DisplayVersion}'"); var project = new Project("Computator.NET", new Dir(@"%ProgramFiles%\Computator.NET", new Files(binariesPath), new File(new Id(nameof(SharedProperties.TslIcon)), SharedProperties.TslIcon)) , new Dir("%Fonts%", Fonts.GetFontFiles()) ) { Version = SharedProperties.Version, GUID = new Guid(SharedProperties.UpgradeCode), UpgradeCode = new Guid(SharedProperties.UpgradeCode), ProductId = _productId, UI = WUI.WixUI_Minimal, LicenceFile = SharedProperties.License, ControlPanelInfo = { Comments = "Computator.NET is a special kind of numerical software that is fast and easy to use but not worse than others feature-wise", Readme = "https://github.com/PawelTroka/Computator.NET", HelpLink = SharedProperties.HelpUrl, HelpTelephone = SharedProperties.HelpTelephone, UrlInfoAbout = SharedProperties.AboutUrl, UrlUpdateInfo = SharedProperties.UpdateUrl, ProductIcon = SharedProperties.IconLocation, Contact = "*****@*****.**", Manufacturer = SharedProperties.Company, InstallLocation = "[INSTALLDIR]", NoModify = true }, BackgroundImage = @"..\Graphics\Installer\InstallShield Computator.NET Theme\welcome.jpg", BannerImage = @"..\Graphics\Installer\InstallShield Computator.NET Theme\banner.jpg", OutDir = System.IO.Path.Combine(SharedProperties.OutDir, $"net{_dottedNetVersion.Replace(".","")}"), OutFileName = "Computator.NET", InstallScope = InstallScope.perMachine,//TODO: investigate if we could somehow go for perUser here //MajorUpgradeStrategy = MajorUpgradeStrategy.Default,//only MajorUpgradeStrategy or MajorUpgrade can be defined MajorUpgrade = new MajorUpgrade { AllowDowngrades = false, AllowSameVersionUpgrades = true, Disallow = false, DowngradeErrorMessage = "A later version of [ProductName] is already installed. Setup will now exit.", IgnoreRemoveFailure = true, Schedule = UpgradeSchedule.afterInstallInitialize, } }; //project.LightOptions += @" XPath=""/wixOutput/table[@name='File']/row/field[5]"" InnerText=""65535.0.0.0"""; //project.WixSourceGenerated += Fonts.InjectFonts; var prerequisite = PrerequisiteHelper.GetPrerequisite(CurrentHighestVersion); Console.WriteLine($"Setting required NetFx {nameof(prerequisite)} '{prerequisite.WixPrerequisite}'"); project.SetNetFxPrerequisite(prerequisite.WixPrerequisite, prerequisite.ErrorMessage); var mainExe = project.ResolveWildCards().FindFile((f) => f.Name.EndsWith("Computator.NET.exe")).Single(); Console.WriteLine($"Main executable is '{mainExe.ToString()}'"); Console.WriteLine("Setting shortcuts.."); mainExe.Shortcuts = new[] { //new FileShortcut("Computator.NET", "INSTALLDIR"){IconFile = SharedProperties.IconLocation}, new FileShortcut("Computator.NET", "%Desktop%") { IconFile = SharedProperties.IconLocation }, new FileShortcut("Computator.NET", @"%ProgramMenu%") { IconFile = SharedProperties.IconLocation }, }; Console.WriteLine("Setting files associations.."); mainExe.Associations = new[] { new FileAssociation("tsl") { Icon = nameof(SharedProperties.TslIcon), Description = "TROKA Scripting Language script file", ContentType = @"text/tsl" }, new FileAssociation("tslf") { Icon = nameof(SharedProperties.TslIcon), Description = "TROKA Scripting Language functions file", ContentType = @"text/tslf" }, }; //project.LaunchConditions.Add(new LaunchCondition()); //project.ControlPanelInfo.NoRepair = true, //project.ControlPanelInfo.NoRemove = true, //project.ControlPanelInfo.SystemComponent = true, //if set will not be shown in Control Panel //Compiler.WixLocation //project.SourceBaseDir = "<input dir path>"; //project.OutDir = "<output dir path>"; Console.WriteLine("Building main project..."); return(project.BuildMsi()); }