Skip to content

Generating strongly typed resource files not currently supported on .NET Core MSBuild  #2272

Description

@livarcocc

From @iSazonov on July 6, 2017 13:41

What is a right repo to ask about ResGen in dotnet build?

Currently I try to generate strongly typed resources and get error:
C:\Users\user\AppData\Local\Microsoft\dotnet\sdk\2.0.0-preview2-006502\Microsoft.Common.CurrentVersion.targets(2921,5): error : Generating strongly typed resource files not currently supported on .NET Core MSBuild [C:\Users\user\Documents\GitHub\iSazonov\PowerShell\src\Microsoft.PowerShell.CoreCLR.Eventing\Microsoft.PowerShell.CoreCLR.Eventing.csproj]

From related Issue https://github.com/dotnet/cli/issues/819:

dotnet-resgen got replaced by the Microsoft.Net.Sdk implementation, so closing this.

Is strongly typed resources supported?

Copied from original issue: dotnet/cli#7084

Activity

  1. livarcocc commented on Jul 7, 2017

    @livarcocc
    ContributorAuthor
  2. livarcocc commented on Jul 7, 2017

    @livarcocc
    ContributorAuthor

    From @iSazonov on July 6, 2017 17:29

    @wli3 Thanks! Please clarify - I don't see strongly typed config in the csproj.

  3. livarcocc commented on Jul 7, 2017

    @livarcocc
    ContributorAuthor

    From @wli3 on July 6, 2017 17:35

    Hi @iSazonov ,
    I think I misunderstood you. Looks like your project is in Github, could you share the specific strongly typed config code link?

  4. livarcocc commented on Jul 7, 2017

    @livarcocc
    ContributorAuthor

    From @iSazonov on July 6, 2017 17:41

    @wli3 I'll publish the sample tomorrow from my local branch.

  5. livarcocc commented on Jul 7, 2017

    @livarcocc
    ContributorAuthor

    From @iSazonov on July 7, 2017 5:34

    I published my test. See last <ItemGroup> in https://github.com/iSazonov/PowerShell/blob/cproj-psversion-from-git-resx/src/Microsoft.PowerShell.CoreCLR.Eventing/Microsoft.PowerShell.CoreCLR.Eventing.csproj

    Build command:

    dotnet msbuild /t:"ResGen" /v:diag /noconsolelogger /fileLogger .\Microsoft.PowerShell.CoreCLR.Eventing.csproj
    or
    dotnet build /t:"ResGen" /v:diag /noconsolelogger /fileLogger .\Microsoft.PowerShell.CoreCLR.Eventing.csproj
    

    I believe error place is here
    Is the project compiled without FEATURE_CODEDOM?

  6. livarcocc commented on Jul 7, 2017

    @livarcocc
    ContributorAuthor

    I am moving this issue over to MSBuild. FYI @rainersigwald

  7. rainersigwald commented on Jul 7, 2017

    @rainersigwald
    Member

    Huh, we should have had an issue open for this already but I couldn't find one.

    Is the project compiled without FEATURE_CODEDOM?

    Yes, it is: CodeDOM wasn't available at the time of the initial port to .NET Core and we haven't lit up this feature after the initial port.

    It looks like CodeDOM is available in .NET Core 2.0 (for code-writing scenarios, though not compilation), so we should be able to enable that feature flag everywhere after we move to targeting .NET Core 2.0.

    Workarounds

    Build with full framework MSBuild.exe (on a Windows machine).

    Check in the (generated) .cs files and update them when necessary (from Windows/full framework).

  8. iSazonov commented on Jul 8, 2017

    @iSazonov

    @rainersigwald Thanks!
    PowerShell Core is multiplatform project and we cannot use MSBuild.exe. Currently we use a simple tool developed by @vors.

    It looks like CodeDOM is available in .NET Core 2.0

    Yes, it is. So I believe it is easy to fix the Issue.

  9. foo-baar commented on Sep 12, 2017

    @foo-baar

    Hello Team, I am sorry if I am asking silly question: So what I understand is that if I am using dotnet sdk on my Mac & vscode for editing, I can't create a strongly typed controller from db ?

    (I know there is visual studio version now available for Mac).
    Thanks 👍

  10. iSazonov commented on Sep 13, 2017

    @iSazonov

    Team, .Net Core 2.0 RTM was out - could you please milestone the Issue?

  11. hrushib commented on Apr 13, 2018

    @hrushib

    @livarcocc, when is this feature going to be supported. Absence of this makes it difficult to build code from Linux, i.e. requires manual overhead of generating and checking in strongly typed resource access wrapper.

  12. rainersigwald commented on Apr 19, 2018

    @rainersigwald
    Member

    From a quick look this morning, CodeDOM is not enough to bring this back: the task also depends on System.Resources.ResXResourceReader which is full-framework only.

  13. 28 remaining items

  14. bergmeister commented on Aug 19, 2019

    @bergmeister

    @rainersigwald I see you've already completed some work in #4420 but you also call out some work such as 'Check to ensure that the reader type is available when not targeting netcoreapp3.0' (which is ticked now).
    Does this mean that a project targeting .Net Standard (2.0) can already auto-generate the *.Designer.cs files (in my case just the simple case of only strings)? Using preview8, it does not seem to do that at the moment or is a property needed to opt into this at the moment for netstandard2.0 projects? Thanks.

  15. rainersigwald commented on Aug 19, 2019

    @rainersigwald
    Member

    @bergmeister That wasn't directly related to code generation, and StronglyTypedResourceGenerator doesn't work in preview8. #4588 should enable it in the future, though.

    If your code is open source, I can add it to the set of things I'm testing before merging that PR. Just feed me a link :)

  16. bergmeister commented on Aug 19, 2019

    @bergmeister

    @rainersigwald Thanks for the quick answer. An example project that you could use for testing is this one: https://github.com/PowerShell/PSScriptAnalyzer/tree/master/Engine
    Just remove the Strings.Designer.cs file, remove the global.json one directory above and then just type dotnet build (all NuGet packages are on NuGet.org so everything should just build out of the box).

  17. bergmeister commented on Sep 14, 2019

    @bergmeister

    @rainersigwald I tried to use Preview9 on my project (links in last comment) but dotnet build does not create me the strongly typed .cs file from .resx file although the csproj has the following:

      <ItemGroup>
        <Compile Update="Strings.Designer.cs">
          <DesignTime>True</DesignTime>
          <AutoGen>True</AutoGen>
          <DependentUpon>Strings.resx</DependentUpon>
        </Compile>
      </ItemGroup>
    
      <ItemGroup>
        <EmbeddedResource Update="Strings.resx">
          <Generator>ResXFileCodeGenerator</Generator>
          <LastGenOutput>Strings.Designer.cs</LastGenOutput>
        </EmbeddedResource>
      </ItemGroup>
    

    Am I am missing something, is there something that needs to be enabled explicitly for a .net standard (2.0) library?

  18. rainersigwald commented on Sep 16, 2019

    @rainersigwald
    Member

    @bergmeister Yes, this is fairly confusing: your build was configured so that building inside Visual Studio would regenerate the source files, but building on the command line would not (regardless of whether it was msbuild.exe or dotnet build doing it).

    When I tested your repo I applied this patch to change to build-time generation in all cases:

    diff --git a/Engine/Engine.csproj b/Engine/Engine.csproj
    index 560ce8d..2fca8db 100644
    --- a/Engine/Engine.csproj
    +++ b/Engine/Engine.csproj
    @@ -46,18 +46,19 @@
         <PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
       </ItemGroup>
     
    -  <ItemGroup>
    +  <!-- <ItemGroup>
         <Compile Update="Strings.Designer.cs">
           <DesignTime>True</DesignTime>
           <AutoGen>True</AutoGen>
           <DependentUpon>Strings.resx</DependentUpon>
         </Compile>
    -  </ItemGroup>
    +  </ItemGroup> -->
     
       <ItemGroup>
         <EmbeddedResource Update="Strings.resx">
           <Generator>ResXFileCodeGenerator</Generator>
    -      <LastGenOutput>Strings.Designer.cs</LastGenOutput>
    +      <StronglyTypedFileName>$(IntermediateOutputPath)\Strings.Designer.cs</StronglyTypedFileName>
    +      <StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
         </EmbeddedResource>
       </ItemGroup>
  19. bergmeister commented on Sep 17, 2019

    @bergmeister

    @rainersigwald Thanks for the info, however, even with the rc1 of .Net Core 3 and your local changes, it does not work for me

  20. rainersigwald commented on Sep 17, 2019

    @rainersigwald
    Member

    @bergmeister Can you please file a new issue with details? How exactly does it fail to work--build error? Runtime failure doing something in particular?

  21. bergmeister commented on Sep 17, 2019

    @bergmeister

    Ok, I can create an issue with a minimized repro.
    It fails on build due to the Strings.Designer.cs not being created by the build (I deleted the file locally as I'd expect dotnet build to create it automatically, is my assumption here right?)

  22. rainersigwald commented on Sep 17, 2019

    @rainersigwald
    Member

    Yes, that's correct--the copy in the checked-in tree is not needed when switching over to build-time generation.

  23. rainersigwald commented on Sep 17, 2019

    @rainersigwald
    Member

    @bergmeister, I think I've reproduced the problem; it looks like something's gone wrong with the namespace/class name that we're generating. Don't worry about minimizing but please do file a bug.

  24. rainersigwald commented on Sep 17, 2019

    @rainersigwald
    Member

    @bergmeister with this I can get your project to compile:

    diff --git a/Engine/Engine.csproj b/Engine/Engine.csproj
    index 560ce8d..e1f143b 100644
    --- a/Engine/Engine.csproj
    +++ b/Engine/Engine.csproj
    @@ -46,18 +46,21 @@
         <PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
       </ItemGroup>
     
    -  <ItemGroup>
    +  <!-- <ItemGroup>
         <Compile Update="Strings.Designer.cs">
           <DesignTime>True</DesignTime>
           <AutoGen>True</AutoGen>
           <DependentUpon>Strings.resx</DependentUpon>
         </Compile>
    -  </ItemGroup>
    +  </ItemGroup> -->
     
       <ItemGroup>
         <EmbeddedResource Update="Strings.resx">
           <Generator>ResXFileCodeGenerator</Generator>
    -      <LastGenOutput>Strings.Designer.cs</LastGenOutput>
    +      <StronglyTypedFileName>$(IntermediateOutputPath)\Strings.Designer.cs</StronglyTypedFileName>
    +      <StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
    +      <StronglyTypedNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</StronglyTypedNamespace>
    +      <StronglyTypedClassName>Strings</StronglyTypedClassName>
         </EmbeddedResource>
       </ItemGroup>
    

    We can chase down exactly why all this is necessary in your bug.

  25. bergmeister commented on Sep 19, 2019

    @bergmeister

    Thanks, it works now with your 2 new lines.
    The StronglyTypedNamespace line seems to be only necessary because we have the following in the csproj (from the days when we converted from project.json to the new csproj format to make it work using Visual Studio)
    <RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace>
    Now that the command line works, we don't care about Visual Studio too much tbh but I will check that later today (using VS 16.2.5 somehow the setting to allow VS to use preview SDKs has gone or can I use the VS Preview for that now only?)
    Is the StronglyTypedClassName property needed due to the resx file not matching the project name? I tried renaming it to Engine.resx and changed the references in the csproj but the property was still needed then.
    Should I file the 'bug' to be specific about this project or rather generic that those properties seem to be needed? As a user I can be flexible, but I'd like to know what is the cleanest/simplest csproj declaration to have this working (optionally also in a way that it works with VS)

  26. rainersigwald commented on Sep 19, 2019

    @rainersigwald
    Member

    File whatever's easiest for you and we can broaden/narrow it as we investigate.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions