Search Unity

Question Problem with script debug in visual studio 2017

Discussion in 'Unity MARS' started by SzJ_hydro, Jun 16, 2020.

  1. SzJ_hydro

    SzJ_hydro

    Joined:
    Jan 8, 2020
    Posts:
    2
    Hi,

    I have problems with mars script debug with visual studio 2017. The generated solution contains the Unity.MARS and Unity.MARS.ContentSamples projets, when I try to build the solution get a lot of errors with missing assemblies. Some time the solution contains more projects and I can build it, but it is unreliable, it is in connection with changing the scripting backend or the api compatibility level. Can you explain to me how can I fix this issue.

    Regards
    Joe
     
  2. jmunozarUTech

    jmunozarUTech

    Unity Technologies

    Joined:
    Jun 1, 2020
    Posts:
    297
    Hello Joe,

    We will need more info about this. what are the errors that you are getting in the Unity Editor?
     
  3. SzJ_hydro

    SzJ_hydro

    Joined:
    Jan 8, 2020
    Posts:
    2
    I get errors in visual studio, not in the unity editor for example "The type or namespace name MARSTraitDataProvider<>' could not be found (are you missing a using directive or an assembly reference?)"
    And if I can't build the visual studio solution I can't debug my scripts.
     
  4. jmunozarUTech

    jmunozarUTech

    Unity Technologies

    Joined:
    Jun 1, 2020
    Posts:
    297
    @SzJ_hydro the issue could well be on how your visual studio is set up. What matters is errors in the Unity Editor since at the end; the engine is what builds your project.
     
  5. Jon-at-Kaio

    Jon-at-Kaio

    Joined:
    Oct 17, 2007
    Posts:
    185
    Errors in visual studio do matter as well when trying to use intellisense to diagnose or write fresh code. admittedly not directly related to the samples, but I'm currently blocked on trying to learn aspects concerning landmarkoutput things as I get similar errors...

    "The type or namespace name 'LandmarkOutputPoint' does not exist in the namespace 'Unity.MARS' (are you missing an assembly reference?)"

    So any help on this would be appreciated.
     
  6. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Hi there!

    I believe you are running into a known issue regarding how Unity's IDE integration packages generate project files. We cover this in a section of the MARS Software Development Guide. When Unity opens your scripts in Visual Studio, it generates a `.sln` file for the whole project and a `.csproj` file for every assembly that you intend to modify. By default, we choose not to generate `.csproj` files for package code, which includes MARS. Normally, the `.csproj` for your code can reference package assemblies via their compiled `.dll`, but because MARS includes some generated code in the `Assets` folder using a `.asmref`, we fall into an edge case where Unity creates a `.csproj` for MARS, but it doesn't actually reference the package code. Instead, this `.csproj` only includes the generated code, and the IDE thinks that most of MARS does not exist.

    Thankfully, you should be able to work around this issue by going to `Preferences > External Tools`, enabling `Generate all .csproj files`, and re-generating your Visual Studio project. The best way to do this is to just delete the `.sln` and `.csproj` files in your project folder and open a script from Unity, which will regenerate these files. MARS includes some code to check this box for you on first import, but it may have failed or you may have had another editor open which overwrote the setting.

    For users of other IDEs, we also recommend updating to the latest IDE integration package in the Unity package manager (`com.unity.ide.vscode` for Visual Studio Code or `com.unity.ide.rider` for Rider). In later versions of the Rider integration, there are multiple options for how to generate `.csproj` files. You will want to select the `Registry Packages` option, among whatever others you prefer.

    Unfortunately, the Visual Studio integration is not upgradeable this way. One way or another, the way to know that you are seeing the same issue I am describing is to search the `Unity.MARS.csproj` file for `Compile Include`. If you only see about a dozen or so files and they're all within `Assets\MARS\Generated`, you need to check that box and re-generate your project files. We have a fix in place for the underlying issue which should be available in later versions of Unity.

    If you are still having issues, and you see the particular types that are missing referenced in `Unity.MARS.csproj` you may have encountered a different issue, which we'd love to know more about. Please let us know if you are still having trouble after trying what I described above.

    Thanks for trying MARS, and good luck creating!
     
  7. Jon-at-Kaio

    Jon-at-Kaio

    Joined:
    Oct 17, 2007
    Posts:
    185
    OK. so I've got a workaround for my lack of ability to properly implement landmarks for the time being (kinda build my own makeshift dodgy thing), but I tried your solution above:-
    The check box was already checked, so I tried deleting the sln csproj (ALL of them) from the project folder and re-generating them which it generated a lot more mars csproj's then were originally there (I originally only had like 8 csproj in total (normal ones and mars ones)) so I though great it worked. But no. I checked the mars.csproj and it did now indeed have a lot more than 12 includes in there so that was good.


    But yeah landmarkoutputpoint etc still aren't available in intellisense etc.
     
  8. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Huh... that's unexpected. I just gave this a try in a fresh project on Windows with Visual Studio Community 2017. I had to fiddle with the setting (uncheck and re-check) for generating .csproj files for it to generate the full set. Once I did get a Unity.MARS.csproj with all of the code referenced, I was able to start typing `LandmarkOut` and saw intellisense pop up for `LandmarkOutputPoint`.

    At this point I think I need to see your project to reproduce the issue. Unfortunately the setting for generating .csproj files is stored in the registry, so I won't be able to completely replicate your environment. Any more specific info (Unity, Visual Studio, Windows versions etc.) you can provide will be helpful. Could you report bug and make sure to include your project? You can do this by going to `Help > Report a bug...` and fill out the form. Make sure that your project folder appears under the Attached Files section. If your project is very large, it may be quicker to create a small sample project that reproduces the issue. Please make sure that the project you submit contains the .csproj files that Unity created. Once you send the report you should receive an e-mail with a link to the report. Please share it here when you have that.

    In lieu of a full bug report, you could try just adding your .sln and .csproj files to a zip and attaching them to this thread. I might be able to compare to what I have on my end or comb through and see if anything looks fishy.

    Thanks for following up on this and sorry that you're having trouble! I'm glad you have found a workaround in the meantime while we solve this problem.
     
  9. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Thanks for the bug report. I was able to see what you were seeing, but eventually got things to work. I think that maybe all that was missing from my previous instructions was to restart Unity as part of the process. I tried deleting the .csproj and .sln files a few times while Unity was running, but when I closed Unity and Visual Studio, and _then_ cleared out the project files, the next try worked.

    To be clear, try the following:
    - Uncomment MarsWallLiner.cs:27 (not sure this is necessary)
    - Close all other instances of the Unity Editor (if there are any)
    - Close all instances of Visual Studio
    - In the last remaining Editor instance, ensure that Preferences > External Tools > Generate all .csproj files is enabled
    - Close Unity and Visual Studio
    - Delete the `.sln` and `.csproj` files in the project folder
    - I also deleted the `.vs` folder. I'm not sure if this is necessary
    - Open Unity on the project and open MarsWallLiner.cs

    On my end, I was seeing `LandmarkOutputPoint` as a missing reference in Visual Studio prior to the restart, but see it referenced now.
     
  10. Jon-at-Kaio

    Jon-at-Kaio

    Joined:
    Oct 17, 2007
    Posts:
    185
    k. Followed your steps to the letter twice (On my Mac) and it didn't resolve the issue, in fact when I went back in it only recreated a fraction of the .csproj files that were there originally. looking the unity.mars.csproj on the mac I see 15 compile includes, which is a lot less than when I tried your previous suggestion on my windows version.

    So I'm going to try these updated steps on my windows version and see if we've made progress there.
    if so then I guess we're looking at an osx related bug.

    So that was strange, I went over to my windows version and it exhibited the same results as the mac version now. only 15 compile includes listed in unity.mars.csproj

    (side note there isn't a .vs folder on osx visual studio projects)
     
    Last edited: Jun 18, 2020
  11. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Oh! I didn't realize you were on Windows and OS X here. FWIW, I've been troubleshooting these issues on both, as well. Sorry that you're still having trouble.

    Are you seeing .csproj files created for other MARS packages like `Unity.XRTools.ModuleLoader` for example? The only thing that I can think of is that the checkbox in Preferences may not be accurately representing the state of the setting on your system. As I was troubleshooting I checked and unchecked that box a few times, and I made sure to have only one instance of the Unity Editor open. If you've done that, I'm not sure what else is different between your system and mine which may contribute to the problem.

    Something else I noticed is that in a new project in 2019.4.0, I see different options and a "Regenerate project files" button under Preferences > External Tools, which means that this version of the Editor has an updated Visual Studio integration. With any luck, your bug has already been fixed! Are you able to upgrade the project to 2019.4.0? Though this is a minor version update, there shouldn't be any breaking API changes. Make sure you have a backup of your project just in case.
     
  12. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    I should add: if you are able to update to 2019.4, make sure that the `Registry Packages` option is checked when you regenerate your project files.
     
    Last edited: Jun 18, 2020
    jmunozarUTech likes this.
  13. cam415

    cam415

    Joined:
    Mar 26, 2014
    Posts:
    46
    That worked!!
    updated to 2019.4. checked "Registry Packages" option and regenerated project files. Thank you!
     
    jmunozarUTech likes this.