Skip to content

Conversation

@viceroypenguin
Copy link
Contributor

@viceroypenguin viceroypenguin commented Nov 10, 2022

Fixes #45

@viceroypenguin
Copy link
Contributor Author

@kzu NB: this is based on top of embedded-resources. Will be easier to read once #132 is merged and this is rebased.

@kzu
Copy link
Member

kzu commented Nov 10, 2022

#132 tested and merged. Rebased this one already for review

@viceroypenguin
Copy link
Contributor Author

Need to fix a bug in the hintname for the generated source file. Will fix in the morning.

Copy link
Member

@kzu kzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very minor changes requested 🙏. This looks great!

@kzu
Copy link
Member

kzu commented Nov 10, 2022

Build failed with: CSC : warning CS8785: Generator 'ResourcesGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'Content/Styles/Custom.css.g.cs' contains an invalid character '/' at position 7. (Parameter 'hintName')' .

Makes sense. You'll just need to replace the path separator with a dot (I think that reads best, instead of an underscore).

@viceroypenguin
Copy link
Contributor Author

Build failed with: CSC : warning CS8785: Generator 'ResourcesGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'Content/Styles/Custom.css.g.cs' contains an invalid character '/' at position 7. (Parameter 'hintName')' .

Makes sense. You'll just need to replace the path separator with a dot (I think that reads best, instead of an underscore).

Yeah - I did it the windows way cause that's what I tested on my machine; forgot about linux machines. Easy fix.

@viceroypenguin viceroypenguin requested a review from kzu November 10, 2022 12:33
@viceroypenguin
Copy link
Contributor Author

NB: I made reference to an image for ThisAssembly.Resources, but my VS system is so heavily color customized that I can't make the image. You mind adding that?

@viceroypenguin
Copy link
Contributor Author

viceroypenguin commented Nov 10, 2022

I tested the build on a linux machine and am not able to replicate on 6.0 RTM (MSBuild version matches version in failing build log):

>> docker run -it --rm mcr.microsoft.com/dotnet/sdk:6.0-alpine
/ # git clone https://github.com/viceroypenguin/ThisAssembly.git
Cloning into 'ThisAssembly'...
remote: Enumerating objects: 1746, done.
remote: Counting objects: 100% (590/590), done.
remote: Compressing objects: 100% (232/232), done.
remote: Total 1746 (delta 471), reused 409 (delta 346), pack-reused 1156
Receiving objects: 100% (1746/1746), 1020.31 KiB | 4.00 MiB/s, done.
Resolving deltas: 100% (1284/1284), done.
/ # cd ThisAssembly/
/ThisAssembly # dotnet build
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
  Restored /ThisAssembly/src/ThisAssembly/ThisAssembly.csproj (in 1.61 sec).
  Restored /ThisAssembly/src/ThisAssembly.Prerequisites/ThisAssembly.Prerequisites.csproj (in 1.61 sec).
  Restored /ThisAssembly/src/ThisAssembly.Strings/ThisAssembly.Strings.csproj (in 1.69 sec).
  Restored /ThisAssembly/src/ThisAssembly.Constants/ThisAssembly.Constants.csproj (in 1.69 sec).
  Restored /ThisAssembly/src/ThisAssembly.Project/ThisAssembly.Project.csproj (in 1.69 sec).
  Restored /ThisAssembly/src/ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.csproj (in 1.69 sec).
  Restored /ThisAssembly/src/ThisAssembly.Metadata/ThisAssembly.Metadata.csproj (in 1.69 sec).
  Restored /ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj (in 3.54 sec).
  ThisAssembly.Prerequisites -> /ThisAssembly/src/ThisAssembly.Prerequisites/bin/Debug/ThisAssembly.Prerequisites.dll
  Created package at /ThisAssembly/bin/ThisAssembly.Prerequisites.42.42.42.nupkg.
  ThisAssembly.Metadata -> /ThisAssembly/src/ThisAssembly.Metadata/bin/Debug/ThisAssembly.Metadata.dll
  ThisAssembly.Project -> /ThisAssembly/src/ThisAssembly.Project/bin/Debug/ThisAssembly.Project.dll
  ThisAssembly.Constants -> /ThisAssembly/src/ThisAssembly.Constants/bin/Debug/ThisAssembly.Constants.dll
  ThisAssembly.AssemblyInfo -> /ThisAssembly/src/ThisAssembly.AssemblyInfo/bin/Debug/ThisAssembly.AssemblyInfo.dll
  ThisAssembly.Strings -> /ThisAssembly/src/ThisAssembly.Strings/bin/Debug/ThisAssembly.Strings.dll
  Created package at /ThisAssembly/bin/ThisAssembly.Constants.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.Strings.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.Metadata.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.Project.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.AssemblyInfo.42.42.42.nupkg.
  ThisAssembly -> /ThisAssembly/src/ThisAssembly/bin/Debug/ThisAssembly.dll
  ThisAssembly.Prerequisites -> /ThisAssembly/src/ThisAssembly.Prerequisites/bin/Debug/ThisAssembly.Prerequisites.dll
  Created package at /ThisAssembly/bin/ThisAssembly.Prerequisites.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.42.42.42.nupkg.
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(12,30): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(23,13): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(36,33): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(38,32): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/EmbeddedResource.cs(8,38): warning CS8601: Possible null reference assignment. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
  ThisAssembly.Tests -> /ThisAssembly/src/ThisAssembly.Tests/bin/Debug/ThisAssembly.Tests.dll

Build succeeded.

/ThisAssembly/src/ThisAssembly.Strings/Model.cs(12,30): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(23,13): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(36,33): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/ThisAssembly.Strings/Model.cs(38,32): warning CS8602: Dereference of a possibly null reference. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/ThisAssembly/src/EmbeddedResource.cs(8,38): warning CS8601: Possible null reference assignment. [/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
    5 Warning(s)
    0 Error(s)

Time Elapsed 00:00:14.63

@kzu
Copy link
Member

kzu commented Nov 10, 2022

I'd just replace the slashes with dots... I'm almost sure you cannot have paths in there...

@viceroypenguin
Copy link
Contributor Author

viceroypenguin commented Nov 10, 2022

I'd just replace the slashes with dots... I'm almost sure you cannot have paths in there...

Correct - See ResourcesGenerator.cs:70-72; note the .Replace(). Works correctly on windows and linux as of c09be94, according to my testing. Not sure why the ubuntu builder failed.

            spc.AddSource(
                $"{resourceName.Replace('\\', '.').Replace('/', '.')}.g.cs", 
                SourceText.From(output, Encoding.UTF8));

@kzu
Copy link
Member

kzu commented Nov 15, 2022

I've got a repro failure in WSL2 Ubuntu 22.04:

Welcome to .NET 6.0!
---------------------
SDK Version: 6.0.403

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Prerequisites/ThisAssembly.Prerequisites.csproj (in 391 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly/ThisAssembly.csproj (in 391 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.csproj (in 399 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Resources/ThisAssembly.Resources.csproj (in 399 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Project/ThisAssembly.Project.csproj (in 398 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Constants/ThisAssembly.Constants.csproj (in 399 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/ThisAssembly.Strings.csproj (in 398 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Metadata/ThisAssembly.Metadata.csproj (in 405 ms).
  Restored /mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj (in 607 ms).
  ThisAssembly.Prerequisites -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Prerequisites/bin/Debug/ThisAssembly.Prerequisites.dll
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Prerequisites.42.42.42.nupkg.
  ThisAssembly.AssemblyInfo -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.AssemblyInfo/bin/Debug/ThisAssembly.AssemblyInfo.dll
  ThisAssembly.Metadata -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Metadata/bin/Debug/ThisAssembly.Metadata.dll
  ThisAssembly.Project -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Project/bin/Debug/ThisAssembly.Project.dll
  ThisAssembly.Strings -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/bin/Debug/ThisAssembly.Strings.dll
  ThisAssembly.Resources -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Resources/bin/Debug/ThisAssembly.Resources.dll
  ThisAssembly.Constants -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Constants/bin/Debug/ThisAssembly.Constants.dll
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Constants.42.42.42.nupkg.
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Resources.42.42.42.nupkg.
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Metadata.42.42.42.nupkg.
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.AssemblyInfo.42.42.42.nupkg.
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Strings.42.42.42.nupkg.
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Project.42.42.42.nupkg.
  ThisAssembly -> /mnt/c/Code/ThisAssembly/src/ThisAssembly/bin/Debug/ThisAssembly.dll
  ThisAssembly.Prerequisites -> /mnt/c/Code/ThisAssembly/src/ThisAssembly.Prerequisites/bin/Debug/ThisAssembly.Prerequisites.dll
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.Prerequisites.42.42.42.nupkg.
  Created package at /mnt/c/Code/ThisAssembly/bin/ThisAssembly.42.42.42.nupkg.
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(12,30): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(23,13): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(32,13): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/Tests.cs(50,54): error CS0117: 'ThisAssembly.Resources' does not contain a definition for 'Content' [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/Tests.cs(54,54): error CS0117: 'ThisAssembly.Resources' does not contain a definition for 'Content' [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(45,33): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(47,32): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Resources/ThisAssembly.ResourcesGenerator/ThisAssembly.Resources.EmbeddedResource.cs(8,38): warning CS8601: Possible null reference assignment. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]

Build FAILED.

/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(12,30): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(23,13): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(32,13): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(45,33): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Strings/Model.cs(47,32): warning CS8602: Dereference of a possibly null reference. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Resources/ThisAssembly.ResourcesGenerator/ThisAssembly.Resources.EmbeddedResource.cs(8,38): warning CS8601: Possible null reference assignment. [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/Tests.cs(50,54): error CS0117: 'ThisAssembly.Resources' does not contain a definition for 'Content' [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/Tests.cs(54,54): error CS0117: 'ThisAssembly.Resources' does not contain a definition for 'Content' [/mnt/c/Code/ThisAssembly/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj]
    6 Warning(s)
    2 Error(s)

@kzu
Copy link
Member

kzu commented Nov 15, 2022

I'm pretty sure you missed checking out the right branch. I cloned clean on WSL, checked-out the right branch, and I'm getting the same failure.

Notice that in your logs, the ThisAssembly.Resources package is never built/created...

  Created package at /ThisAssembly/bin/ThisAssembly.Constants.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.Strings.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.Metadata.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.Project.42.42.42.nupkg.
  Created package at /ThisAssembly/bin/ThisAssembly.AssemblyInfo.42.42.42.nupkg.

Copy link
Member

@kzu kzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out why this one generator is not being run on linux (repro on WSL and hosted runner alike)

@viceroypenguin
Copy link
Contributor Author

I'm pretty sure you missed checking out the right branch. I cloned clean on WSL, checked-out the right branch, and I'm getting the same failure.

Notice that in your logs, the ThisAssembly.Resources package is never built/created...

.... /sigh

Anyway, fixed now, hopefully...

@kzu
Copy link
Member

kzu commented Nov 16, 2022

Ok, now it's just unit tests, should be far easier to fix 😉

@viceroypenguin
Copy link
Contributor Author

Ok, now it's just unit tests, should be far easier to fix 😉

Yup. Saw that, but was already in bed... 😀 Will look later today

@viceroypenguin viceroypenguin requested a review from kzu November 19, 2022 20:54
@kzu
Copy link
Member

kzu commented Nov 26, 2022

How do you feel about renaming IsText with a Kind="Text" instead? Would resemble the original implementation with Type, which I think is more flexible should we provide additional specific support for other kinds of embedded resources...

@viceroypenguin
Copy link
Contributor Author

Thought about that, but couldn't come up with a safe name. Updated. Thanks! :)

@kzu
Copy link
Member

kzu commented Nov 30, 2022

Ok, this is looking great! The final thing would be running dotnet format on the repo root to fix the dotnet-format check and it's ready for merging!! 🎉🎉

@kzu kzu merged commit e26779f into devlooped:main Nov 30, 2022
@viceroypenguin viceroypenguin deleted the embedded-resources branch November 30, 2022 18:45
@kzu kzu added the enhancement New feature or request label Dec 31, 2022
@devlooped devlooped locked and limited conversation to collaborators Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ThisAssembly.Resources

2 participants