Rabadash8820/UnityAssemblies

Linux improvements

njlr opened this issue · 8 comments

njlr commented

This doesn't quite work on Linux out-of-the-box.

The problem is that Unity Hub will install Unity into the user's home directory. To work-around this, a csproj / fsproj must have the following:

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <UnityVersion>2019.4.13f1</UnityVersion>
    <UnityInstallRoot>/home/your_username_here/Unity/Hub/Editor/</UnityInstallRoot>
  </PropertyGroup>

The problem with this is that the install root depends on the username, meaning that the project file is not portable between developers.

Would it possible to add a search-path for the user's home directory by default?

Thanks for a great library!

njlr commented

The work-around is to add a Directory.Build.props file to root of the project folder like this:

<Project>
 <PropertyGroup>
  <TargetFramework>netstandard2.0</TargetFramework>
  <UnityVersion>2019.4.13f1</UnityVersion>
  <UnityInstallRoot>/home/your_username_here/Unity/Hub/Editor/</UnityInstallRoot>
 </PropertyGroup>
</Project>

This should be kept out of source-control, since it will vary by machine.

@njlr Thanks for reporting this. Sorry for the delayed response, I just realized that I hadn't set GitHub to watch all activity in this repo!

Anyway, I'm glad you brought this up because I haven't actually tested this package out on Linux yet (the NuGet description technically says "on Mac or Windows", which is how I sleep at night 😆). Your Directory.Build.props approach is clever, but I disagree that all of those properties will vary by machine. Trying to collaborate on a project with different Unity versions is a nightmare, so I expect that teams will always want TargetFramework and UnityVersion to be versioned. Letting users override UnityInstallRoot in this way could work, but there may be a simpler way to get the current user's home directory, like I'm betting there's some MSBuild property to help with that. I'll have to do a little research...

@njlr Actually, I might be overthinking this. Couldn't you just use ~/Unity/Hub/Editor? I'm not sure if MSBuild expands the ~ character correctly, but I don't see why it wouldn't.

njlr commented

@njlr Actually, I might be overthinking this. Couldn't you just use ~/Unity/Hub/Editor? I'm not sure if MSBuild expands the ~ character correctly, but I don't see why it wouldn't.

Yeah that's the problem, MSBuild doesn't like the ~

@njlr Okay, how about this... If you set UnityInstallRoot in your csproj to the following, does the build succeed on Linux?

<UnityInstallRoot>$([System.Environment]::GetFolderPath('System.Environment+SpecialFolder.UserProfile'))/Unity/Hub/Editor/</UnityInstallRoot>

I've tested that the crazy GetFolderPath property function syntax resolves correctly on Windows, but I don't have a Linux machine on hand to test with (other than WSL distros, which I don't totally trust to represent your use case).

njlr commented

@njlr Okay, how about this... If you set UnityInstallRoot in your csproj to the following, does the build succeed on Linux?

<UnityInstallRoot>$([System.Environment]::GetFolderPath('System.Environment+SpecialFolder.UserProfile'))/Unity/Hub/Editor/</UnityInstallRoot>

I've tested that the crazy GetFolderPath property function syntax resolves correctly on Windows, but I don't have a Linux machine on hand to test with (other than WSL distros, which I don't totally trust to represent your use case).

Yes, seems to work!

Awesome! 🙂 Well that solves the versioned path issue. I should have a new version of the NuGet in a day or two with these changes. Please let me know if u find any other broken paths on Linux!

@njlr These Linux paths are now available in the latest package release.