msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

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

Open livarcocc opened this issue 9 years ago • 48 comments

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

livarcocc avatar Jul 07 '17 20:07 livarcocc

From @wli3 on July 6, 2017 17:9

Hi iSazonov, Could you try to add resx files like this? https://github.com/dotnet/sdk/blob/cd25d6bbfc2aac61cc790c511900427ac64fdaa8/TestAssets/TestProjects/KitchenSink/TestApp/TestApp.csproj#L24 (This is a part of SDK automatic test asset)

livarcocc avatar Jul 07 '17 20:07 livarcocc

From @iSazonov on July 6, 2017 17:29

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

livarcocc avatar Jul 07 '17 20:07 livarcocc

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?

livarcocc avatar Jul 07 '17 20:07 livarcocc

From @iSazonov on July 6, 2017 17:41

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

livarcocc avatar Jul 07 '17 20:07 livarcocc

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?

livarcocc avatar Jul 07 '17 20:07 livarcocc

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

livarcocc avatar Jul 07 '17 20:07 livarcocc

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).

rainersigwald avatar Jul 07 '17 21:07 rainersigwald

@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.

iSazonov avatar Jul 08 '17 15:07 iSazonov

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 👍

foo-baar avatar Sep 12 '17 06:09 foo-baar

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

iSazonov avatar Sep 13 '17 05:09 iSazonov

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

ghost avatar Mar 13 '18 00:03 ghost

@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.

hrushib avatar Apr 13 '18 15:04 hrushib

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.

rainersigwald avatar Apr 19 '18 15:04 rainersigwald

Should we open an API proposal for ResXResourceReader in CoreFX repo? https://github.com/dotnet/corefx/issues/12565 and https://github.com/Microsoft/msbuild/issues/1352 seem related issues.

ghost avatar Apr 19 '18 16:04 ghost

Discussed with @rainersigwald offline. I think it is worth trying to bring this back without waiting for ResXResourceReader (whose port is not scheduled currently)

My suspicion (just from browsing the code) is that ResxResourcrReader/ResXDataNode are not necessary for this scenario. StronglyTypedResourceBuilder hardly depends on them and it looks like those code paths can probably be removed.

Happily MSBuild happens to already have a copy of StronglyTypedResourceBuilder.cs because I guess historically they had a reason for avoiding a dependency on System.Design.dll. (Maybe it was only in the SDK?). I compared it with .NET Framework's current copy and it's basically the same.

I think someone could take a shot at wiring this up now.

danmoseley avatar Apr 19 '18 18:04 danmoseley

@kasper3 any interst in taking a look?

danmoseley avatar Apr 19 '18 18:04 danmoseley

@danmosemsft, I tried building msbuild master on Windows 10, msbuild\build.cmd -hostType Core and getting errors like:

C:\Users\kasper.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018: at LibGit2Sharp.Core.Proxy.git_revwalk_next(RevWalkerHandle walker) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\TaskUsageLogger\TaskUsageLogger.csproj]

Tried in three modes: Developer Command Prompt VS2017, normal cmd, normal PowerShell.

ghost avatar Apr 19 '18 22:04 ghost

Uh, I have no idea what that means. Is there any more information like callstack or message? Is this a fresh new clone - if not I would delete it and clone again?

danmoseley avatar Apr 19 '18 22:04 danmoseley

I just cloned the repo, tip of master branch. Call stack:

C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018: LibGit2Sharp.NotFoundException: object not found - no match for id (7c1f7a8cd8f2b844046892036912db28a7ec4c37) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.Core.Proxy.git_revwalk_next(RevWalkerHandle walker) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at LibGit2Sharp.CommitLog.CommitEnumerator.MoveNext() [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle..ctor(String projectDirectory, Repository repo, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
C:\Users\kasper\.nuget\packages\nerdbank.gitversioning\2.1.23\build\Nerdbank.GitVersioning.targets(63,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() [C:\Users\kasper\Source\Repos\msbuild\src\Samples\XmlFileLogger\XmlFileLogger.csproj]
git log -1
commit e8b480c373eadd9daa975c6e96e4dbbabcd9a4fe

ghost avatar Apr 19 '18 23:04 ghost

Shallow clone? https://github.com/libgit2/libgit2sharp/issues/1351

danmoseley avatar Apr 19 '18 23:04 danmoseley