Skip to content
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

Usage with .NET 8 projects using the 'UseArtifactsOutput' build option #15

Open
Numpsy opened this issue Dec 4, 2023 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@Numpsy
Copy link

Numpsy commented Dec 4, 2023

Hi,

I had a go at running Covenant on a project that uses the 'UseArtifactsOutput' build option that was added in .NET 8 (which causes all the 'obj' directories to get put under a single 'artifacts' directory under the build root), and that failed as it couldn't find the project.assets.json file.

I haven't had much of a look at the issue, but I guess it might be down to
https://github.com/patriksvensson/covenant/blob/afaa6d6b83d00f9cbe8005f2091f521cb4a4dbfd/src/Covenant/Analysis/Dotnet/DotnetAnalyzer.cs#L223C38-L223C38
which looks for the assets file in a fixed location under the directory containing the project file.

@patriksvensson patriksvensson added the enhancement New feature or request label Dec 4, 2023
@patriksvensson
Copy link
Owner

Yes, that's probably why it can't find it.

@Numpsy
Copy link
Author

Numpsy commented Dec 4, 2023

I'm not sure offhand what the best way to get the 'real' path from the project tools (Buildalyzer or Microsoft.Build.* etc) is.
Using the .NET 8 SDK you can do things like

dotnet build --getProperty:BaseIntermediateOutputPath

to get the path, but that won't work with older sdks.

@Numpsy
Copy link
Author

Numpsy commented Jan 21, 2024

It looks like you can get the path to the assets file by doing the design time build and getting the ProjectAssetsFile property from the results. However, it currently does a design time build based on data in the assets file and doesn't do it if it can't read the assets, so I think it'd need reworking a bit to do that.

I also tried making it execute dotnet build --getProperty:ProjectAssetsFile and read the output and that seems to work as well, though it's working with external processes rather than library calls.

@panoukos41
Copy link

Hello, coming accross the same problem I believe if the --design-time-build was to be executed before the generation maybe at the start of the Analyze method we could acquire the correct project.assets.json file using the csproj and then pass it to the ReadAssetFile as expected.

While AnalyzeProject could just accept the var (version, copyright) as arguments.

Using a local fork with this code inside ReadAssetFile worked as expected for finding the asset file.

var analyzer = _analyzerManager.GetProject(path.FullPath);
var result = analyzer.Build().Results.FirstOrDefault();
path = result.GetProperty("ProjectAssetsFile"); // gets the project.assets.json path

@patriksvensson would you be intrseted in this? And could I give it a try to kind of support UseArtifactsOutput when the --design-time-build flag is used? Or add a new flag depending on what you want 😄 .

@patriksvensson
Copy link
Owner

@panoukos41 Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants