dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

Globbing and DependsUpon with resx files and custom tool doesn't quite work #2873

Closed bradphelan closed 4 years ago

bradphelan commented 7 years ago

Here is a fun example of bad behaviour of globbing and the project system. I have

  <ItemGroup>
    <Compile Update="Properties\*.resx.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>%(Filename)</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Properties\*.resx">
      <Generator>I18NReactive</Generator>
      <LastGenOutput>%(Filename).resx.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

where I18NReactive is a custom single file generator I wrote. The globbing and dependencies work at first glance.

image

Then I right click and select run custom tool to regen the resx.cs file. And not only does it update the file it also updates my csproj file. 👎 so now it is

  <ItemGroup>
    <Compile Update="Properties\*.resx.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>%(Filename)</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Properties\*.resx">
      <Generator>I18NReactive</Generator>
      <LastGenOutput>%(Filename).resx.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

  <ItemGroup>
    <Compile Update="Properties\lang.resx.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>lang.resx</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Properties\lang.resx">
      <Generator>I18NReactive</Generator>
      <LastGenOutput>lang.resx.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

that's kinda wierd no?

I also tried

 <ItemGroup>
    <Compile Remove="Properties\*.resx.cs" />
    <Compile Include="Properties\*.resx.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>%(Filename)</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Remove="Properties\*.resx" />
    <EmbeddedResource Include="Properties\*.resx">
      <Generator>I18NReactive</Generator>
      <LastGenOutput>%(Filename).resx.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>
Pilchie commented 6 years ago

@jviau - would this be project-system, or core CPS?

clairernovotny commented 6 years ago

It's nasty, but here's a glob that works for Resx/embedded resources: https://github.com/onovotny/MSBuildSdkExtras/blob/master/MSBuild.Sdk.Extras/build/MSBuild.Sdk.Extras.Common.targets#L14-L28

I see the same stuff getting added to the project file when you run the tool.

jviau commented 6 years ago

This is CPS. I have identified the issue, single file generator is rewriting all property, causing us to expand them all. We will fix this soon.

Pilchie commented 6 years ago

Nice - @jviau is there an ID for the issue on the CPS side?

jviau commented 6 years ago

https://devdiv.visualstudio.com/DevDiv/VS%20IDE%20CPS/_queries/edit/470015

Pilchie commented 6 years ago

Great - closing as external then. If you can - it would be great to comment here on the expected release with the fix once it's merged.

SimonCropp commented 4 years ago

@Pilchie did this ever get a release?

davkean commented 4 years ago

@davidwengier We had a bunch of changes both in single file generators and editing since above - can we verify if this still exists? The internal bug was won't fix but we've had feedback here and https://github.com/Microsoft/msbuild/issues/2352#issuecomment-454076634.

davidwengier commented 4 years ago

Internal PR here: https://devdiv.visualstudio.com/DevDiv/_git/CPS/pullrequest/217519

SimonCropp commented 4 years ago

i also note that renaming a parent file, that has dependents globbed under it, results in those dependents being explicitly duplicated in the csproj. will the fix for this issue also resolve that?

davkean commented 4 years ago

@SimonCropp No, can you file a new one for that here?

SimonCropp commented 4 years ago

@davkean done https://github.com/dotnet/project-system/issues/5706

davidwengier commented 4 years ago

This has been fixed.