mob-sakai/CSharpCompilerSettingsForUnity

Updating to 1.4.0 from 1.3.0 fails with with Unity 2020.1.17

KuraiAndras opened this issue ยท 6 comments

Describe the bug
Updated my project from 1.3.0 to 1.4.0 with Unity 2020.1.17 and not all of my sources are compiled

To Reproduce
Can't really

Expected behavior
All sources compile

Screenshots
image

Environment (please complete the following information):

  • Version 1.4.0
  • Platform: Editor/Windows
  • Unity version: 2020.1.17
  • Build options: .Net 4.x

Additional context
The problem might come from the fact that we are using external .cs files added as unity packages. We have several projects included like:

[package.json]
"bimvisualizer.shared": "file:../../BimVisualizer.Shared",

These point to folders with .net standard 2.0 projects (which are using C#9.0) (also the bin and obj folders are renamed to .bin and .obj so unity will not try to use the dlls inside them). The errors seem to only come from one project where c# 9 and 8 are used, and not from the unity project.

Should I include another folder for assemblies in the settings?

@KuraiAndras
The asmdef files under the Packages directory are excluded by default.
(Prefix ! means "should be excluded.")

image


Solution 1:

  • Project Settings > C# Compiler > Compiler > Included Assemblies
  • Set Packages/your_package_name/ instead of !Packages/
    • e.g. Packages/com.bim.visualizer.shared/

Solution 2:

  • Select the asmdef file under the Packages directory
  • Turn on Enable C# Compiler Settings in inspector
  • Choose the compiler package and the language version
  • Click Apply

To be precise, we have multiple projects, and they are not located in the packages folder. The structure is like:

bimvisualizer.shared
    |   bimvisualizer.shared.asmdef
    |   package.json
bimvisualizer.application
    |   bimvisualizer.application.asmdef
    |   package.json
*etc
bimvisualizer.unity
    |   Packages
        | manifest.json
        | package-lock.json
    |   Assets
        |   multiple asmdefs, assets, etc

In this context what does the Packages folder refer to? [UnityProject]/Packages or [UnityProject]/Library/PackageCache or just whatever folder the UPM resolves when reading the mainfest?

Also why is the Packages folder excluded by default?

@KuraiAndras

Check name field in bimvisualizer.shared/package.json and bimvisualizer.application/package.json.

For example:

[bimvisualizer.shared/package.json]
{
  "name": "com.bim.visualizer.shared",
  "version": "1.0.0",
  ...
}

and

[bimvisualizer.application/package.json]
{
  "name": "com.bim.visualizer.application",
  "version": "1.0.0",
  ...
}
  • Remove !Packages/
  • Add Packages/com.bim.visualizer.shared
  • Add Packages/com.bim.visualizer.application

Also why is the Packages folder excluded by default?

This is to prevent unintended compiler changes and to minimize the impact of compiler changes.
Packages and store assets should (essentially) be compiled with the default compiler.

I'll try this and get back to you soon

Yupp, the project wors, after including the assemblies like : Packages/package.name.etc .
You can close this now if you want.

Also could you provide some documentation on this in the readme?

๐Ÿ‘

Also could you provide some documentation on this in the readme?

Sure.