Search Unity

.rsp files settings not propagated to .csproj

Discussion in 'Scripting' started by rtm223, Feb 3, 2021.

  1. rtm223

    rtm223

    Joined:
    Apr 12, 2017
    Posts:
    28
    I've noticed when setting warnings as errors in my packages, using csc.rsp files, that these settings are respected by Unity, but not by Visual Studio and as far as I can tell this is because the generated .csproj files are not being generated to respect them.

    For example, in my rsp file:
    Code (csharp):
    1. -warn:4
    2. -warnaserror+
    3. -warnaserror-:612,618
    If I then create a warning in a csharp file, i.e.
    #warning hello
    this will appear in Visual Studio as a warning but (correctly) as an error in Unity.

    Looking at the .csproj file for my project, there's nothing in there that I would expect to see for warnings as errors, i.e. something like:

    Code (csharp):
    1.     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    2.     <WarningLevel>4</WarningLevel>
    3.     <NoWarn></NoWarn>
    4.     <WarningsAsErrors></WarningsAsErrors>
    5.     <WarningsNotAsErrors>612,618</WarningsNotAsErrors>
    This is true across Unity 2018, 2019 and 2020, so I'm wondering if there is some additional hoop I need to jump through to get warnings as errors in Visual Studio?
     
    bdovaz likes this.
  2. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    We are notifying MS about this :) As I agree that would be the expected behaviour.
     
    rtm223 and bdovaz like this.
  3. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Hello we added this to our backlog.

    As a workaround (and probably now a better way, compared to response files) you can use a `Directory.Build.props` file along your generated projects files. Visual Studio will automatically pick them, and they are not altered by the project re-generation process so it is now the perfect way to enhance project files.

    More information here:
    https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019

    Thank you and best regards.
     
    bdovaz likes this.
  4. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    Thank you, I hope you solve it soon.

    And about the workaround, without an example I'm afraid I don't understand it very well, my knowledge in that subject is zero.
     
  5. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Sure, just create a file name Directory.Build.props along with your generated csproj files, with the following content:

    <Project>
    <PropertyGroup>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsNotAsErrors>612,618</WarningsNotAsErrors>
    </PropertyGroup>
    </Project>
     
    marllon_helloello, mbaker and bdovaz like this.
  6. fjjoubert

    fjjoubert

    Joined:
    Oct 10, 2021
    Posts:
    3
    Is there a way to do this for vs code as well? I tried adding a Directory.Build.props file with the content above to my project in vscode but nothing happens. I am trying to treat warnings as errors in both unity and vscode.