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
61 changes: 61 additions & 0 deletions Documentation/docs-mobile/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,67 @@ If `DebugType` is not set or is the empty string, then the
`DebugSymbols` property controls whether or not the Application is
debuggable.

## DiagnosticAddress

A value provided by `dotnet-dsrouter` such as `127.0.0.1`, the IP
address component of `$(DiagnosticConfiguration)` or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `127.0.0.1`.

## DiagnosticConfiguration

A value provided by `dotnet-dsrouter` for `$DOTNET_DiagnosticPorts` such as:

* `127.0.0.1:9000,suspend,connect`
* `127.0.0.1:9000,nosuspend,connect`

Note that the `,` character will need to be escaped with `%2c` if
passed in command-line to `dotnet build`:

```dotnetcli
dotnet build -c Release -p:DiagnosticConfiguration=127.0.0.1:9000%2csuspend%2cconnect
```

This will automatically set the `$DOTNET_DiagnosticPorts` environment
variable packaged inside the application.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

## DiagnosticListenMode

A value provided by `dotnet-dsrouter` such as `connect`, the listening
mode component of `$(DiagnosticConfiguration)` or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `connect`.

## DiagnosticPort

A value provided by `dotnet-dsrouter` such as `9000`, the port
component of `$(DiagnosticConfiguration)` or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `9000`.

## DiagnosticSuspend

A boolean value provided by `dotnet-dsrouter` such as `true/suspend`
or `false/nosuspend`, a component of `$(DiagnosticConfiguration)`
or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `false`.

## EmbedAssembliesIntoApk

A boolean property that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
<AndroidEnableRestrictToAttributes Condition=" '$(AndroidEnableRestrictToAttributes)' == '' ">obsolete</AndroidEnableRestrictToAttributes>

<!-- Mono components -->
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == ''">$(EnableDiagnostics)</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == ''">false</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' ">$(EnableDiagnostics)</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' and ('$(DiagnosticConfiguration)' != '' or '$(DiagnosticAddress)' != '' or '$(DiagnosticPort)' != '' or '$(DiagnosticSuspend)' != '' or '$(DiagnosticListenMode)' != '') ">true</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' ">false</AndroidEnableProfiler>

<!--
Android package (apt/aab) alignment, expressed as the page size in kilobytes. Two values are supported: 4 and 16.
Expand All @@ -60,6 +61,16 @@
<AndroidZipAlignment Condition=" '$(AndroidZipAlignment)' == '' ">16</AndroidZipAlignment>
</PropertyGroup>

<PropertyGroup Condition=" '$(AndroidEnableProfiler)' == 'true' and '$(DiagnosticConfiguration)' == '' ">
<DiagnosticAddress Condition=" '$(DiagnosticAddress)' == '' ">127.0.0.1</DiagnosticAddress>
<DiagnosticPort Condition=" '$(DiagnosticPort)' == '' ">9000</DiagnosticPort>
<DiagnosticSuspend Condition=" '$(DiagnosticSuspend)' == '' ">false</DiagnosticSuspend>
<DiagnosticListenMode Condition=" '$(DiagnosticListenMode)' == '' ">connect</DiagnosticListenMode>
<DiagnosticConfiguration>$(DiagnosticAddress):$(DiagnosticPort),$(DiagnosticListenMode)</DiagnosticConfiguration>
<DiagnosticConfiguration Condition=" '$(DiagnosticSuspend)' == 'true' ">$(DiagnosticConfiguration),suspend</DiagnosticConfiguration>
<DiagnosticConfiguration Condition=" '$(DiagnosticSuspend)' != 'true' ">$(DiagnosticConfiguration),nosuspend</DiagnosticConfiguration>
</PropertyGroup>

<!-- User-facing configuration-specific defaults -->
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<AndroidLinkMode Condition=" '$(AndroidLinkMode)' == '' ">None</AndroidLinkMode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1289,19 +1289,29 @@ public void AbiNameInIntermediateOutputPath ()
}

[Test]
public void PackageNamingPolicy ([Values ("LowercaseMD5", "LowercaseCrc64")] string packageNamingPolicy)
[TestCase (true, "LowercaseMD5", "")]
[TestCase (true, "LowercaseCrc64", "")]
[TestCase (false, "", "127.0.0.1:9000,suspend,connect")]
public void EnvironmentVariables (bool useInterpreter, string packageNamingPolicy, string diagnosticConfiguration)
{
var proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("UseInterpreter", "true");
proj.SetProperty ("AndroidPackageNamingPolicy", packageNamingPolicy);
proj.SetProperty ("UseInterpreter", useInterpreter.ToString ());
if (!string.IsNullOrEmpty (packageNamingPolicy))
proj.SetProperty ("AndroidPackageNamingPolicy", packageNamingPolicy);
if (!string.IsNullOrEmpty (diagnosticConfiguration))
proj.SetProperty ("DiagnosticConfiguration", diagnosticConfiguration);
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
var environment = b.Output.GetIntermediaryPath (Path.Combine ("__environment__.txt"));
FileAssert.Exists (environment);
var values = new List<string> ();
values.Add ("mono.enable_assembly_preload=0");
values.Add ("DOTNET_MODIFIABLE_ASSEMBLIES=Debug");
var values = new List<string> {
"mono.enable_assembly_preload=0",
};
if (useInterpreter)
values.Add ("DOTNET_MODIFIABLE_ASSEMBLIES=Debug");
if (!string.IsNullOrEmpty (diagnosticConfiguration))
values.Add ($"DOTNET_DiagnosticPorts={diagnosticConfiguration}");
Assert.AreEqual (string.Join (Environment.NewLine, values), File.ReadAllText (environment).Trim ());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,7 @@ because xbuild doesn't support framework reference assemblies.
<ItemGroup>
<_GeneratedAndroidEnvironment Include="mono.enable_assembly_preload=0" Condition=" '$(AndroidEnablePreloadAssemblies)' != 'True' " />
<_GeneratedAndroidEnvironment Include="DOTNET_MODIFIABLE_ASSEMBLIES=Debug" Condition=" '$(AndroidIncludeDebugSymbols)' == 'true' and '$(AndroidUseInterpreter)' == 'true' " />
<_GeneratedAndroidEnvironment Include="DOTNET_DiagnosticPorts=$(DiagnosticConfiguration)" Condition=" '$(DiagnosticConfiguration)' != '' " />
Copy link
Member

Choose a reason for hiding this comment

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

Any risk this might get stuck in the build or would a new build and/or run without any Diagnostic* properties set remove all diagnostic support in the build making sure this part of the build gets updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

This part looks OK for incremental builds, this target has no Inputs/Outputs, so it always runs.

Then <WriteLinesToFile/> uses WriteOnlyWhenDifferent="True", which would update the timestamp on the @(AndroidEnvironment) file it writes if changed.

Later on, it looks like all the important targets will rerun if @(AndroidEnvironment) files change.

</ItemGroup>
<WriteLinesToFile
File="$(IntermediateOutputPath)__environment__.txt"
Expand Down
10 changes: 10 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,12 +1054,17 @@ public void FastDeployEnvironmentFiles (bool isRelease, bool embedAssembliesInto
}
}
};
proj.SetProperty ("DiagnosticAddress", "127.0.0.1");
proj.SetProperty ("DiagnosticPort", "9000");
proj.SetProperty ("DiagnosticSuspend", "false");
proj.SetProperty ("DiagnosticListenMode", "connect");
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"
Console.WriteLine (""Foo="" + Environment.GetEnvironmentVariable(""Foo""));
Console.WriteLine (""Bar34="" + Environment.GetEnvironmentVariable(""Bar34""));
Console.WriteLine (""Empty="" + Environment.GetEnvironmentVariable(""Empty""));
Console.WriteLine (""MONO_GC_PARAMS="" + Environment.GetEnvironmentVariable(""MONO_GC_PARAMS""));
Console.WriteLine (""DOTNET_MODIFIABLE_ASSEMBLIES="" + Environment.GetEnvironmentVariable(""DOTNET_MODIFIABLE_ASSEMBLIES""));
Console.WriteLine (""DOTNET_DiagnosticPorts="" + Environment.GetEnvironmentVariable(""DOTNET_DiagnosticPorts""));
");
var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
Expand Down Expand Up @@ -1093,6 +1098,11 @@ public void FastDeployEnvironmentFiles (bool isRelease, bool embedAssembliesInto
logcatOutput,
"The Environment variable \"MONO_GC_PARAMS\" was not set to expected value \"bridge-implementation=new\"."
);
StringAssert.Contains (
"DOTNET_DiagnosticPorts=127.0.0.1:9000,connect,nosuspend",
logcatOutput,
"The Environment variable \"DOTNET_DiagnosticPorts\" was not set to expected value \"127.0.0.1:9000,connect,nosuspend\"."
);
// NOTE: set when $(UseInterpreter) is true, default for Debug mode
if (!isRelease) {
StringAssert.Contains (
Expand Down
Loading