-
Notifications
You must be signed in to change notification settings - Fork 386
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
Don't copy intermediate translated files #9159
Merged
tmeschter
merged 2 commits into
dotnet:main
from
tmeschter:230712-IncludeResourceAssemblies
Jul 13, 2023
Merged
Don't copy intermediate translated files #9159
tmeschter
merged 2 commits into
dotnet:main
from
tmeschter:230712-IncludeResourceAssemblies
Jul 13, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By default we translate all `XamlPropertyRule`, `XamlPropertyRuleNoCodeBehind`, and `XamlPropertyProjectItemsSchema` items via xliff-tasks. The `XlfOutputItem` metadata on the items specifies what kind of MSBuild item xliff-tasks produces for each translated file. Currently we specify `EmbeddedResource` because we want to embed the translated files in our resource DLLs. When xliff-tasks creates the items it also copies over all the metadata from the original item--including the value of `CopyToOutputDirectory`. We'll get back to that in a moment. The items created by xliff-tasks represent intermediate files that still need some adjustment. For example, if the input file is AnalyzerReference.xaml, the Spanish translation will be AnalyzerReference.es.xaml. When we ship the file we want it to have the original name but live under a locale-specific folder, like es\AnalyzerReference.xaml. The `CopyTranslatedXamlRulesToOutputDirectory` target takes care of this for us. However, the intermediate items are still `EmbeddedResources` with `CopyToOutputDirectory` set to `PreserveNewest`. So the standard targets that handle copying to the output directory find these intermediate `EmbeddedResource` items and, indeed, copy them. One effect of this is that they get copied into the NPM package we produce for C# Dev Kit even though they will never get used from that location (even if they had the right name and directory structure). While these files are functionally harmless they make the NPM package much larger and will also impose maintenance costs--future devs will have to waste time trying to understand why they are present and what they do. The fix here is to have xliff-tasks put these intermediate files into an intermediate item, `_TranslatedXamlRule`. We then have a target, `CreateEmbeddedResourceForTranslatedXamlRules`, that handles creating the `EmbeddedResource` items but resets the `CopyToOutputDirectory` metadata. Since we have now put all the translated XAML rules into their own convenient item group we also update `CopyTranslatedXamlRulesToOutputDirectory` to use that instead of digging through all the `EmbeddedResource`s to find the ones it cares about. This reduces the NPM package to the expected files: a couple of assemblies and some package metadata files. > Aside: Whether or not it is desirable to embed all these files as resources and whether or not we are doing it correctly such that CPS can find them at runtime are open questions that I do not attempt to address here.
Add a test to verify the contents of the NPM package produced for C# Dev Kit.
drewnoakes
reviewed
Jul 13, 2023
Comment on lines
+11
to
+15
[UsesVerify] | ||
public sealed class PackageContentTests | ||
{ | ||
[Fact] | ||
public Task NpmPackage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
drewnoakes
approved these changes
Jul 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to AB#1849781.
By default we translate all
XamlPropertyRule
,XamlPropertyRuleNoCodeBehind
, andXamlPropertyProjectItemsSchema
items via xliff-tasks. TheXlfOutputItem
metadata on the items specifies what kind of MSBuild item xliff-tasks produces for each translated file. Currently we specifyEmbeddedResource
because we want to embed the translated files in our resource DLLs. When xliff-tasks creates the items it also copies over all the metadata from the original item--including the value ofCopyToOutputDirectory
. We'll get back to that in a moment.The items created by xliff-tasks represent intermediate files that still need some adjustment. For example, if the input file is AnalyzerReference.xaml, the Spanish translation will be AnalyzerReference.es.xaml. When we ship the file we want it to have the original name but live under a locale-specific folder, like es\AnalyzerReference.xaml. The
CopyTranslatedXamlRulesToOutputDirectory
target takes care of this for us.However, the intermediate items are still
EmbeddedResources
withCopyToOutputDirectory
set toPreserveNewest
. So the standard targets that handle copying to the output directory find these intermediateEmbeddedResource
items and, indeed, copy them. One effect of this is that they get copied into the NPM package we produce for C# Dev Kit even though they will never get used from that location (even if they had the right name and directory structure). While these files are functionally harmless they make the NPM package much larger and will also impose maintenance costs--future devs will have to waste time trying to understand why they are present and what they do.The fix here is to have xliff-tasks put these intermediate files into an intermediate item,
_TranslatedXamlRule
. We then have a target,CreateEmbeddedResourceForTranslatedXamlRules
, that handles creating theEmbeddedResource
items but resets theCopyToOutputDirectory
metadata. Since we have now put all the translated XAML rules into their own convenient item group we also updateCopyTranslatedXamlRulesToOutputDirectory
to use that instead of digging through all theEmbeddedResource
s to find the ones it cares about.This reduces the NPM package to the expected files: a couple of assemblies and some package metadata files.
Microsoft Reviewers: Open in CodeFlow