Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't place a shortcut on the desktop to the main exe #1650

Open
kglundgren opened this issue Oct 1, 2024 · 2 comments
Open

Can't place a shortcut on the desktop to the main exe #1650

kglundgren opened this issue Oct 1, 2024 · 2 comments

Comments

@kglundgren
Copy link

Hello,

As the title says, I can't place a shortcut on the desktop to the main exe. This is my code:

using System.Runtime.CompilerServices;
using WixSharp;
using File = WixSharp.File;

[assembly: InternalsVisibleTo(assemblyName: "WixSharp_MSI_Installer.aot")] // assembly name + '.aot suffix

static string GetRootDir([CallerFilePath] string filePath = "") =>
    $@"{Path.GetDirectoryName(filePath)!}\..";

var projectName = "MyApp";

string rootDir = GetRootDir();
var appPublishDir = $@"{rootDir}\build\app-x64-rel";
var buildDir = $@"{rootDir}\build\wix";

if (!Directory.Exists(buildDir)) Directory.CreateDirectory(buildDir);
Directory.GetFiles(buildDir).ForEach(System.IO.File.Delete);

var installDir = $@"%ProgramFiles%\MyOrg AB\{projectName}";
Id installDirId = new("INSTALLDIR");

var mainExeFileName = $"{projectName}.exe";
var mainExePath = $@"{appPublishDir}\{projectName}";
Id mainExeId = new("MainExe");

var installerResources = $@"{rootDir}\WixSharp_MSI_Installer\Resources";

Console.WriteLine($"main exe id: {mainExeId}");

var project = new ManagedProject(projectName,
    new Dir(id: installDirId, targetPath: installDir,
        new Files(@"*.*", f => !f.EndsWith(mainExeFileName)),
        new File(id: mainExeId, sourcePath: mainExePath,
            new FileShortcut(name: projectName, location: "%Desktop%")
            {
                WorkingDirectory = installDir,
            })
        ))
{
    Platform = Platform.x64,
    GUID = new Guid("33f767ca-a96f-48f7-9fc9-30b2aa777489"),
    SourceBaseDir = appPublishDir,
    OutDir = buildDir,
    LicenceFile = $@"{installerResources}\CustomLicense.rtf",
};

project.BuildMsi();

That gives me this warning and error:

warning WIX1077: The 'Shortcut.MainExe.MyApp_.WorkDir' Property contains '[ProgramFilesFolder]' in its value which is an illegal reference to another property. If this value is a string literal, not a property reference, please ignore this warning. To set a property with the value of another property, use a CustomAction with Property and Value attributes.
error WIX0094: The identifier 'Directory:Shortcut.MainExe.MyApp_.WorkDir' could not be found. Ensure you have typed the reference correctly and that all the necessary inputs are provided to the linker.

I tried changing WorkingDirectory of the shortcut to the installDirId and then I don't get any errors but the shortcut is not created.

I've tried looking for the documentation on how to create shortcuts but haven't been able to find any, if there are I apologize. I tried looking at the samples and copying them but they didn't help either.

@kglundgren
Copy link
Author

I tried changing the code to this, using ExeFileShortcut instead, but it still doesn't work:

using System.Runtime.CompilerServices;
using WixSharp;
using File = WixSharp.File;

[assembly: InternalsVisibleTo(assemblyName: "WixSharp_MSI_Installer.aot")] // assembly name + '.aot suffix

static string GetRootDir([CallerFilePath] string filePath = "") =>
    $@"{Path.GetDirectoryName(filePath)!}\..";

var projectName = "MyApp";
var mainExe = $"{projectName}.exe";

string rootDir = GetRootDir();
var appPublishDir = $@"{rootDir}\build\app-x64-rel";
var buildDir = $@"{rootDir}\build\wix";

if (!Directory.Exists(buildDir)) Directory.CreateDirectory(buildDir);
Directory.GetFiles(buildDir).ForEach(System.IO.File.Delete);

var installerResources = $@"{rootDir}\WixSharp_MSI_Installer\Resources";

var project = new ManagedProject(projectName,
    new Dir($@"%ProgramFiles%\MyOrg AB\{projectName}",
        new Files(@"*.*", f => !f.EndsWith(mainExe)),
        new File(sourcePath: $@"{appPublishDir}\{mainExe}")),
    new Dir("%Desktop%",
        new ExeFileShortcut(name: projectName, target: $@"[INSTALLDIR]{mainExe}", arguments: "")
        {
            WorkingDirectory = "[INSTALLDIR]" }
        ))
{
    Platform = Platform.x64,
    GUID = new Guid("33f767ca-a96f-48f7-9fc9-30b2aa777489"),
    SourceBaseDir = appPublishDir,
    OutDir = buildDir,
    LicenceFile = $@"{installerResources}\CustomLicense.rtf",
};

project.BuildMsi();

@kglundgren
Copy link
Author

Wait, it does work... The shortcuts are just placed in C:\Users\Public\Desktop. I had no idea this directory even existed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants