Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Use dotnet strong typed resource builder #12355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5f12cde
5ea39a8
88f22bd
35df12d
94136ad
b7742a4
863e9bb
7e7cf9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ | |
|
|
||
| <TargetFramework>net5.0</TargetFramework> | ||
| <LangVersion>8.0</LangVersion> | ||
| <PublishReadyToRun>true</PublishReadyToRun> | ||
| <PublishReadyToRun Condition=" '$(Configuration)' != 'Debug' ">true</PublishReadyToRun> | ||
|
|
||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
|
|
@@ -111,6 +111,27 @@ | |
| <HighEntropyVA>true</HighEntropyVA> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <StronglyTypedOutputFolder>gen</StronglyTypedOutputFolder> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name = "CreateDirectories" BeforeTargets = "BeforeResGen"> | ||
| <MakeDir | ||
| Directories = "$(StronglyTypedOutputFolder)"/> | ||
| </Target> | ||
|
|
||
| <ItemGroup> | ||
| <!-- We skip this for Microsoft.Management.UI.Internal because we have to use a workaround for WPF project. See https://github.com/microsoft/msbuild/issues/4751 --> | ||
| <EmbeddedResource Update = "resources/*.resx" Condition = "'$(MSBuildProjectName)' != 'Microsoft.Management.UI.Internal'"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment that this is a workaround for dotnet/msbuild#4751
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| <Generator>ResXFileCodeGenerator</Generator> | ||
| <StronglyTypedLanguage>CSharp</StronglyTypedLanguage> | ||
|
|
||
| <StronglyTypedFileName>$(StronglyTypedOutputFolder)/%(Filename).cs</StronglyTypedFileName> | ||
| <StronglyTypedClassName>%(Filename)</StronglyTypedClassName> | ||
| <StronglyTypedManifestPrefix>$(RootNamespace).resources</StronglyTypedManifestPrefix> | ||
| </EmbeddedResource> | ||
| </ItemGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <DefineConstants>$(DefineConstants);CORECLR</DefineConstants> | ||
| <IsWindows Condition="'$(IsWindows)' =='true' or ( '$(IsWindows)' == '' and '$(OS)' == 'Windows_NT')">true</IsWindows> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -430,10 +430,10 @@ Fix steps: | |
|
|
||
| # handle ResGen | ||
| # Heuristic to run ResGen on the fresh machine | ||
| if ($ResGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.ConsoleHost/gen")) { | ||
| Write-Log -message "Run ResGen (generating C# bindings for resx files)" | ||
| Start-ResGen | ||
| } | ||
| #if ($ResGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.ConsoleHost/gen")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should do more clean-up or file an issue to do it
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, after MSFT team confirm that the PR is good I will clean up all scripts. |
||
| # Write-Log -message "Run ResGen (generating C# bindings for resx files)" | ||
| # Start-ResGen | ||
| #} | ||
|
|
||
| # Handle TypeGen | ||
| # .inc file name must be different for Windows and Linux to allow build on Windows and WSL. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop" ToolsVersion="15.0"> | ||
| <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop" ToolsVersion="15.0" InitialTargets = "PSResources"> | ||
| <Import Project="..\..\PowerShell.Common.props" /> | ||
| <PropertyGroup> | ||
| <Description>Assembly containing WPF code for Out-GridView, HelpWindow, and Show-Command</Description> | ||
|
|
@@ -12,6 +12,66 @@ | |
| <DefineConstants>$(DefineConstants);CORECLR</DefineConstants> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <StronglyTypedOutputFolder>gen</StronglyTypedOutputFolder> | ||
| <SkipWPFcsproj>$([System.String]::Copy('$(MSBuildProjectFile)').Contains('wpftmp'))</SkipWPFcsproj> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name = "CreateDirectories" BeforeTargets = "PSResources"> | ||
| <MakeDir | ||
| Directories = "$(StronglyTypedOutputFolder)"/> | ||
| </Target> | ||
|
|
||
| <ItemGroup> | ||
| <!-- We have to use the workaround for the WPF project. | ||
| .Net 5 Preview.2 has some issues with WPF projects: | ||
| - Strong typed resources does not work as expected out of box. | ||
| (Really they are not generated at all.) | ||
| So we assign items in 'PSEmbeddedResource' to expected format | ||
| and explicitly call 'GenerateResource' task from custom 'PSResources' target. | ||
| - .Net 5 Preview.2 generates a temporory csproj file | ||
| that duplicates call our custom 'PSResources' target. | ||
| To avoid this we skip a project with 'wpftmp' in name. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iSazonov Thanks for this work! I have 3 concerns:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resx files are converted to cs files well for me when I run Start-PSBuild. Or I don't understand your question? I see no activity in MSBuild and SDK. They use tricky way to compile WPF but I don't think they are going to change this now. It seems strong typed resources are rarely used in while and in this sense it is less maintainable.
I guess you are thinking about daily enhancements. In fact, our compile workflow is stable for years. So why not solve the following:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I checked out the The following screenshot is what I get after opening
Just so I'm clear, you agree that the
I'm not thinking about enhancement, but purely maintenance, e.g. something changed (either dotnet sdk or the PS project itself) and we have to change this target to make it continue to work ...
It's not clear to me how this will help solving those 2 issues,
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The files are generated in obj\ folder where *.resource are. If Start-PSBuild success you have the files.
ResGen tool is not changed for years. We don't any maintenance.
Currently we have to use Build.psm1 module to build PowerShell. Third-party distribution maintainers have to port the module to bash shell to build PowerShell without PowerShell. If we change the module we break their process, they have to port again. If all build logic is in csproj files they get updates automatically.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Found the
I agree that's a benefit, but personally, I don't think it's convincing ... I personally don't want to incorporate everything into msbuild, as I personally believe a script is more maintainable than black magic in msbuild 😄
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems I can repo. It seems it is OmniSharp issue. After I restart VS Code I see the reds. Then I run Start-PSBuild and the reds goes away.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did run
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the same. Open SMA folder - I see the reds. Run dotnet build from the folder - the reds goes away.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iSazonov are you running from
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After switching to the branch I run |
||
| --> | ||
| <PSEmbeddedResource Include = "resources/*.resx" Condition = "'$(SkipWPFcsproj)' == 'false'"> | ||
| <Generator>ResXFileCodeGenerator</Generator> | ||
| <StronglyTypedLanguage>CSharp</StronglyTypedLanguage> | ||
|
|
||
| <PublicClass>$([System.String]::new('%(Filename)').StartsWith('Public', System.StringComparison.OrdinalIgnoreCase))</PublicClass> | ||
|
|
||
| <StronglyTypedManifestPrefix>$(RootNamespace).resources</StronglyTypedManifestPrefix> | ||
| <StronglyTypedManifestPrefix Condition = "'%(PublicClass)' == 'true'">$(RootNamespace).resources.public</StronglyTypedManifestPrefix> | ||
|
|
||
| <StronglyTypedFileName>$(StronglyTypedOutputFolder)/%(Filename).cs</StronglyTypedFileName> | ||
| <StronglyTypedFileName Condition = "'%(PublicClass)' == 'true'">$(StronglyTypedOutputFolder)/$([System.String]::Copy('%(Filename)').Substring(7)).cs</StronglyTypedFileName> | ||
|
|
||
| <StronglyTypedClassName>%(Filename)</StronglyTypedClassName> | ||
| <StronglyTypedClassName Condition = "'%(PublicClass)' == 'true'">$([System.String]::Copy('%(Filename)').Substring(7))</StronglyTypedClassName> | ||
|
|
||
| <ManifestResourceName>$(RootNamespace).resources.%(PSEmbeddedResource.StronglyTypedClassName)</ManifestResourceName> | ||
| <ManifestResourceName Condition = "'%(PublicClass)' == 'true'">$(RootNamespace).resources.public.%(PSEmbeddedResource.StronglyTypedClassName)</ManifestResourceName> | ||
| </PSEmbeddedResource> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="PSResources" Condition = "'$(SkipWPFcsproj)' == 'false'"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you should be declaring your Target's Inputs and Outputs, similar to Arcade's resource generator. |
||
| <GenerateResource | ||
| Sources="@(PSEmbeddedResource)" | ||
| UseSourcePath="true" | ||
| StateFile="$(StronglyTypedOutputFolder)/$(MSBuildProjectFile).GenerateResource.cache" | ||
| StronglyTypedClassName="%(PSEmbeddedResource.StronglyTypedClassName)" | ||
| StronglyTypedFileName="%(PSEmbeddedResource.StronglyTypedFileName)" | ||
| StronglyTypedLanguage="%(PSEmbeddedResource.StronglyTypedLanguage)" | ||
| StronglyTypedNamespace="%(PSEmbeddedResource.StronglyTypedNamespace)" | ||
| StronglyTypedManifestPrefix="%(PSEmbeddedResource.StronglyTypedManifestPrefix)" | ||
| PublicClass="%(PSEmbeddedResource.PublicClass)" | ||
| OutputResources="@(PSEmbeddedResource->'$(StronglyTypedOutputFolder)/%(ManifestResourceName).resources')" | ||
| ExecuteAsTool="false" | ||
| MSBuildRuntime="$(GenerateResourceMSBuildRuntime)" | ||
| MSBuildArchitecture="$(GenerateResourceMSBuildArchitecture)"> | ||
|
|
||
| </GenerateResource> | ||
| </Target> | ||
|
|
||
| <ItemGroup> | ||
| <Resource Include="resources\Graphics\Add16.png" /> | ||
| <Resource Include="resources\Graphics\CloseTile16.png" /> | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.