Open davidwengier opened 4 years ago
Good idea. Two notes to improve it:
DependentUpon
should not contain a path. So it can be simplified to
$([System.IO.Path]::ChangeExtension(%(Filename), '.resx'))
*.Designer.cs
files can be prevented by only applying the <Compile Update="">
tag to the *.Designer.cs
files that are matching one of the files updated with the <EmbeddedResource Update="">
tag. Here is an example: https://github.com/novotnyllc/MSBuildSdkExtras/blob/4c901f06673714a051dd1c0c306d3d2a1ed4d0d7/Source/MSBuild.Sdk.Extras/DefaultItems/Platforms/Common.props#L28-L48
The important part here is that the *.Designer.cs
filename is saved as a new metadata (GenFilePath
) in the EmbeddedResource
. Later the <Compile Update="">
tag is then only applied to those files.Can this issue cover .settings and their related Designer.cs files as well? It seems almost exactly the same as the .resx situation.
<None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
<Compile Update="Properties\Settings.Designer.cs" DependentUpon="Settings.settings" DesignTimeSharedInput="True" AutoGen="True" />
In Windows Forms we had few reports (e.g., https://github.com/dotnet/winforms/issues/6849) where customers had resources with non-standard names, and that caused the designer to fail
The following workaround appears the help in establishing the dependency correctly:
<ItemGroup>
<_EmbeddedResources Include="**\*.resx">
<_HasLocaleName>$([System.String]::Copy('%(Filename)').IndexOf('.'))</_HasLocaleName>
</_EmbeddedResources>
<_EmbeddedResourceWithLocaleNames Include="@(_EmbeddedResources)"
Exclude="@(_EmbeddedResources->HasMetadata('_HasLocaleName')->WithMetadataValue('_HasLocaleName','-1'))" />
<EmbeddedResource Update="@(_EmbeddedResourceWithLocaleNames)">
<DependentUpon>$([System.String]::Copy('%(Identity)').SubString(0, $([System.String]::Copy('%(Identity)').IndexOf('.')))).cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
Once #2873 is fixed we can potentially include more metadata into the default glob in the SDK for
EmbeddedResource
to simplify the project file with respect to resource files (*.resx).For example, consider if the SDK was expanded to the following:
This would mean that the act of adding a
.resx
file to a project would result in no changes to the project file. Any pre-existing (standard) configuration in project files could be removed if users want to clean up their project files. Automatic or manual running of the custom tool for a.resx
file also wouldn't modify the project.The problem with the above is the assumption that
*.Designer.cs
is solely for.resx
files, which doesn't hold true for Windows Forms apps, and possibly others. We could go half-way and just include theEmbeddedResource
item above, which would result in some cleanup of the file, but not all.We should investigate if there are ways to make the whole thing possible. One option to investigate is if we can change the filename for the generated designer files for
.resx
files to make them more uniquely identifiable, likeResource1.resx.designer.cs
, though doing that in a backwards compatible way would present a challenge. Other possibilities should be considered.