SDK style CSProj fixes#468
Conversation
|
The CI fails with public api warnings because I marked a few functions as public to be able to unittest them. Is there another pattern to use here that doesn't trip this warning? |
|
there is a new .bat to update the reference file. See UpdateVerifiedPublicApi.bat |
This didn't do anything - or does it write a file that's hidden from git output? |
|
@sylvainfortin I think the question from tobias is for you! |
|
Make sure you run: dotnet test Sharpmake.PublicApiTests/Sharpmake.PublicApiTests.csproj prior to use UpdateVerifiedPublicApi.bat. It will generate the necessary .received.txt it needs to accept as the verified file. Sorry for the inconvenience. This step should be added to UpdateVerifiedPublicApi.bat so it work even if these tests haven't ran. |
|
Still seems to fail? |
|
I think the file Sharpmake.PublicApiTests/Snapshots/Sharpmake.Generators.PublicApi.verified.txt was wrongly updated. It's like the PublicApiTests were ran from a Posix environment where line ending is '\n'. Unfortunately, there are some problematic constant string in the public API that need to be removed. Because line endings in them are not consistent depending the runtime environment. To fix your build, just remove Sharpmake.Generators.PublicApi.verified.txt changes from the commit. |
It was done on Windows - but I have a git setting to normalize the line-endings, so that's probably it. |
|
But it still doesn't work. Should I just remove the unittest using the public symbol and make it private again? |
|
@tru You added public static string ReadOrGenerateGuidFromProjectFile(string projectFile) but I don't see it in the verifiedapi txt file |
I just committed what the script generated. I am fine with just reverting the visibility changes and remove the tests if that's simpler. |
|
Then my bad. I asked @tru to revert Sharpmake.Generators.PublicApi.verified.txt entirely but didn't notice the added method in that file. |
|
I asked claude to fix the issue and it did it with a entry in .gitattributes - it seems to work now. |
|
|
||
| // SDK-style csproj files omit <ProjectGuid>. Generate a stable GUID from the | ||
| // normalised file path so that solution references remain consistent across runs. | ||
| internal static string GenerateDeterministicGuid(string projectFile) |
There was a problem hiding this comment.
There is already a Sharpmake.Util.BuildGuid method that is pretty much similar to this.
| return new Guid(hash).ToString("D").ToUpperInvariant(); | ||
| } | ||
|
|
||
| public static string ReadOrGenerateGuidFromProjectFile(string projectFile) |
There was a problem hiding this comment.
this method should be internal. it is only used in this file and in nunit tests.
| *.reg text eof=crlf | ||
| *.csproj text eof=crlf | ||
|
|
||
| # Declare files that must keep lf |
There was a problem hiding this comment.
I don't like this fix. We will try something else.
| var guid1 = Sln.ReadOrGenerateGuidFromProjectFile(path); | ||
| var guid2 = Sln.ReadOrGenerateGuidFromProjectFile(path); | ||
|
|
||
| Assert.That(guid2, Is.EqualTo(guid1), "deterministic GUID must be stable across calls"); |
There was a problem hiding this comment.
I think it should also check that it doesn't return null
| var guid1 = Sln.ReadOrGenerateGuidFromProjectFile(path1); | ||
| var guid2 = Sln.ReadOrGenerateGuidFromProjectFile(path2); | ||
|
|
||
| Assert.That(guid2, Is.Not.EqualTo(guid1), "different files must get different GUIDs"); |
There was a problem hiding this comment.
same comment than above
Modern SDK-style .csproj files (net5+) omit <ProjectGuid>. ResolveReferencesByPath stored the null result of ReadGuidFromProjectFile directly into UserData["Guid"], causing a NullReferenceException when the .sln generator tried to write the project entry template. The project-level path (ProjectReferencesByPathContainer) would throw ArgumentNullException via new Guid(null). Add ReadOrGenerateGuidFromProjectFile that falls back to a deterministic MD5-based GUID derived from the normalised file path when no <ProjectGuid> is present. The generated GUID is stable across runs, so .sln files remain reproducible without requiring every project to declare one explicitly. Add unit tests covering old-style GUID extraction, null return for SDK-style files, and the deterministic fallback properties.
…in solution folders Adds a new case-insensitive dictionary on Solution.Configuration that maps absolute project paths to solution folder strings. ResolveReferencesByPath applies the mapping so projects added via ProjectReferencesByPath can be placed in nested solution folders instead of always appearing at the root. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…thod Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
… API snapshot The verbatim string constants in Bff.Template.cs contain actual newlines, so their public API snapshot representation changes between LF and CRLF checkouts. Pin this file to LF so the verified snapshot is consistent on all platforms. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ert snapshot/gitattributes - Make ReadOrGenerateGuidFromProjectFile internal (only used in Sln.cs and tests) - GenerateDeterministicGuid now reuses Util.BuildGuid instead of duplicating MD5 code - Revert .gitattributes line-ending changes (rejected approach) - Revert Sharpmake.Generators.PublicApi.verified.txt to base now that the helper is internal and no longer part of the public API - Assert generated GUIDs are non-null in SlnTest Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Review addressed and retested. The problem with the LF stuff in the string file is that I have my machine configured to do autocrlf=input - which is the recommendation these days on Windows, but that means that the file get's checked out as LF on my local machine and that made the test break for me. I think .gitattributes in some way would fix this issue - or the test could account for the LF/CRLF change. |
When integrating our hardcoded SDK-style csproj into the sharpmake project we ran into a crash that was
related to the fact that those csproj solutions don't have a generated GUID. So we will generate a stable
one instead.
Second fix is that there was no way to put a reference into a folder. That was fairly small and easy to fix.
I used Claude to write the tests since nothing was written for this yet.