Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ Use ‘main’ for bug fixes that don’t require API changes. For new features

- [Testing Wiki](https://github.com/dotnet/maui/wiki/Testing)

## Generating PublicAPI Files

If you've added new public APIs and are getting build errors about missing API declarations, you'll need to update the PublicAPI files. You can generate the PublicAPI files manually by building a project with the `PublicApiType=Generate` property:

```dotnetcli
dotnet build ./src/Controls/src/Core/Controls.Core.csproj /p:PublicApiType=Generate
```

This approach will generate the `PublicAPI.Unshipped.txt` files for that specific project. You may need to run this for each project that has new public APIs.

**Note:** If you're still having troubles with PublicAPI errors, you can delete all the content in the relevant `PublicAPI.Unshipped.txt` files and then run the command above to regenerate them completely.


## Stats

Expand Down
10 changes: 10 additions & 0 deletions docs/DevelopmentTips.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ for IntelliSense and other tasks to initialize. If the project hasn't 'settled'

The below parameters can be used with the `dotnet cake` command in the root of your locally cloned .NET MAUI repository folder.

#### PublicAPI Management
`--target=publicapi`
- Clears and regenerates PublicAPI.Unshipped.txt files across all MAUI projects (Core, Controls, Essentials, Graphics)
- Use this when you've added new public APIs and are getting build errors about missing API declarations
- Automatically skips Windows-specific files when not running on Windows, and always skips Tizen files

```bash
dotnet cake --target=publicapi
```

#### Clean
`--clean`
- Occasionally, when switching branches or syncing with the main branch, incremental builds may stop working. A common fix for this is to use git clean -xdf to delete all locally cached build information. However, the issue with git clean -xdf is that it will also wipe out any uncommitted changes. Using --clean to recursively delete the local obj/bin folders should hopefully resolve the issue while preserving your changes.
Expand Down
60 changes: 60 additions & 0 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,66 @@ Task("GenerateCgManifest")
});
});

Task("publicapi")
.Description("Clears PublicAPI.Unshipped.txt files and regenerates them with current public APIs. Processes Core, Controls, Essentials, and Graphics projects. Skips Windows files on non-Windows platforms and always skips Tizen files. Use after adding new public APIs to resolve build errors.")
.Does(() =>
{
var corePublicApiDir = MakeAbsolute(Directory("./src/Core/src/PublicAPI"));
var controlsPublicApiDir = MakeAbsolute(Directory("./src/Controls/src/Core/PublicAPI"));
var essentialsPublicApiDir = MakeAbsolute(Directory("./src/Essentials/src/PublicAPI"));
var graphicsPublicApiDir = MakeAbsolute(Directory("./src/Graphics/src/Graphics/PublicAPI"));

Information("Resetting PublicAPI.Unshipped.txt files...");

// Find and clear all PublicAPI.Unshipped.txt files in Core, Controls, Essentials, and Graphics
var coreUnshippedFiles = GetFiles($"{corePublicApiDir}/**/PublicAPI.Unshipped.txt");
var controlsUnshippedFiles = GetFiles($"{controlsPublicApiDir}/**/PublicAPI.Unshipped.txt");
var essentialsUnshippedFiles = GetFiles($"{essentialsPublicApiDir}/**/PublicAPI.Unshipped.txt");
var graphicsUnshippedFiles = GetFiles($"{graphicsPublicApiDir}/**/PublicAPI.Unshipped.txt");
var allUnshippedFiles = coreUnshippedFiles.Concat(controlsUnshippedFiles).Concat(essentialsUnshippedFiles).Concat(graphicsUnshippedFiles);

foreach(var file in allUnshippedFiles)
{
// Skip Windows-specific files if not on Windows
if (!IsRunningOnWindows() && file.FullPath.Contains("windows"))
{
Information($"Skipping Windows file (not on Windows): {file}");
continue;
}

// Skip Tizen-specific files
if (file.FullPath.Contains("tizen"))
{
Information($"Skipping Tizen file: {file}");
continue;
}

// Skip macOS-specific files
if (file.FullPath.Contains("macos"))
{
Information($"Skipping macOS file: {file}");
continue;
}

Information($"Clearing: {file}");
System.IO.File.WriteAllText(file.FullPath, string.Empty);
}

Information("Regenerating PublicAPI...");

// Build Controls.Core.csproj with PublicApiType=Generate
var settings = new DotNetBuildSettings
{
Configuration = "Debug",
MSBuildSettings = new DotNetMSBuildSettings()
};
settings.MSBuildSettings.Properties["PublicApiType"] = new List<string> { "Generate" };

DotNetBuild("./src/Controls/src/Core/Controls.Core.csproj", settings);

Information("PublicAPI reset and regeneration completed!");
});

bool RunPackTarget()
{
// Is the user running the pack target explicitly?
Expand Down
Loading
Loading