Skip to content

Commit 31f0e87

Browse files
[release/9.0.1xx] [msbuild] Compute DOTNET_DiagnosticPorts using MSBuild properties. (#23629)
If you run `dotnet-dsrouter ios`, it says: Start an application on ios device with ONE of the following environment variables set: [Default Tracing] DOTNET_DiagnosticPorts=127.0.0.1:9000,nosuspend,listen [Startup Tracing] DOTNET_DiagnosticPorts=127.0.0.1:9000,suspend,listen Setting `$DOTNET_DiagnosticPorts` is non-trivial, so as a step to simplify this, we are adding multiple MSBuild properties to configure this value. This would allow the log message to say: Build and run an iOS application such as: [Default Tracing] dotnet run -c Release -p:ios-arm64 -p:DiagnosticAddress=127.0.0.1 -p:DiagnosticPort=9000 -p:DiagnosticSuspend=false -p:DiagnosticListenMode=listen [Startup Tracing] dotnet run -c Release -p:ios-arm64 -p:DiagnosticAddress=127.0.0.1 -p:DiagnosticPort=9000 -p:DiagnosticSuspend=true -p:DiagnosticListenMode=listen Since these are all default values, it can be simplified to: Build and run an iOS application such as: [Default Tracing] dotnet run -p:ios-arm64 -c Release -p:EnableDiagnostics=true [Startup Tracing] dotnet run -p:ios-arm64 -c Release -p:EnableDiagnostics=true Setting any of the new properties also implicitly means that `$(EnableDiagnostics)` is set to `true` (first example), or alternatively `$(EnableDiagnostics)` can be set to true to get the default value for all the new properties (second example). Ref: dotnet/android#10351 Backport of #23429. --------- Co-authored-by: Jonathan Peppers <[email protected]>
1 parent 3e5be17 commit 31f0e87

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

docs/building-apps/build-properties.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,80 @@ The output path to use when device-specific builds are enabled.
279279

280280
Applicable to all platforms that support device-specific builds (currently iOS and tvOS).
281281

282+
## DiagnosticAddress
283+
284+
The IP address where `dotnet-dsrouter` is executing. This is typcially
285+
`127.0.0.1` when profiling on the simulator, and the IP address of the machine
286+
where `dotnet-dsrouter` when profiling on a device.
287+
288+
This is the IP address component of [DiagnosticConfiguration](#diagnosticconfiguration)`.
289+
290+
Implicitly sets [EnableDiagnostics](#enablediagnostics) to `true`.
291+
292+
Defaults to `127.0.0.1`.
293+
294+
## DiagnosticConfiguration
295+
296+
A value provided by `dotnet-dsrouter` for `DOTNET_DiagnosticPorts` such as:
297+
298+
* `127.0.0.1:9000,suspend,connect`
299+
* `127.0.0.1:9000,nosuspend,connect`
300+
301+
Note that the `,` character will need to be escaped with `%2c` if
302+
passed in command-line to `dotnet build`:
303+
304+
```dotnetcli
305+
dotnet build -c Release -p:DiagnosticConfiguration=127.0.0.1:9000%2csuspend%2cconnect
306+
```
307+
308+
This will automatically set the `DOTNET_DiagnosticPorts` environment variable
309+
packaged inside the application, so that the environment variable is set when
310+
the app launches.
311+
312+
Implicitly sets [EnableDiagnostics](#enablediagnostics) to `true`.
313+
314+
The default behavior is to compute this value from the other diagnostics
315+
properties ([DiagnosticAddress](#diagnosticaddress),
316+
[DiagnosticPort](#diagnosticport),
317+
[DiagnosticListenMode](#diagnosticlistenmode), and
318+
[DiagnosticSuspend](#diagnosticsuspend)).
319+
320+
If set, any of the other diagnostic properties will be ignored.
321+
322+
## DiagnosticListenMode
323+
324+
A value provided by `dotnet-dsrouter` such as `connect` or `listen`, the
325+
listening mode component of
326+
[DiagnosticConfiguration](#diagnosticconfiguration)`.
327+
328+
Implicitly sets [EnableDiagnostics](#enablediagnostics) to `true`.
329+
330+
Defaults to `listen`.
331+
332+
## DiagnosticPort
333+
334+
A value provided by `dotnet-dsrouter` such as `9000`, the port
335+
component of [DiagnosticConfiguration](#diagnosticconfiguration)`.
336+
337+
Implicitly sets [EnableDiagnostics](#enablediagnostics) to `true`.
338+
339+
Defaults to `9000`.
340+
341+
## DiagnosticSuspend
342+
343+
A value that specifies the startup behavior when profiling an application.
344+
345+
Set to `true` to suspend the app at startup (waiting for the diagnostics
346+
server to connect to the app) or `false` to launch the app as usual (and
347+
connect the diagnostics server to the app later).
348+
349+
This corresponds with the `suspend/nosuspend` value in
350+
[DiagnosticConfiguration](#diagnosticconfiguration)`.
351+
352+
Implicitly sets [EnableDiagnostics](#enablediagnostics) to `true`.
353+
354+
Defaults to `false`.
355+
282356
## DittoPath
283357

284358
The full path to the `ditto` executable.

msbuild/Xamarin.Shared/Xamarin.Shared.props

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,20 @@ Copyright (C) 2020 Microsoft. All rights reserved.
237237
<!-- that also encapsulates whether we're a library or not (this makes conditions simpler) -->
238238
<_BundleOriginalResources Condition="'$(OutputType)' == 'Library' And '$(IsAppExtension)' != 'true' And '$(BundleOriginalResources)' == 'true'">true</_BundleOriginalResources>
239239

240-
<EnableDiagnostics Condition="'$(EnableDiagnostics)' == '' And '$(_BundlerDebug)' == 'true'">true</EnableDiagnostics>
240+
<EnableDiagnostics Condition="'$(EnableDiagnostics)' == '' And ('$(DiagnosticConfiguration)' != '' Or '$(DiagnosticAddress)' != '' Or '$(DiagnosticPort)' != '' Or '$(DiagnosticSuspend)' != '' Or '$(DiagnosticListenMode)' != '')">true</EnableDiagnostics>
241+
</PropertyGroup>
242+
243+
<PropertyGroup Condition="'$(EnableDiagnostics)' == 'true' And '$(DiagnosticConfiguration)' == ''">
244+
<DiagnosticAddress Condition="'$(DiagnosticAddress)' == ''">127.0.0.1</DiagnosticAddress>
245+
<DiagnosticPort Condition="'$(DiagnosticPort)' == ''">9000</DiagnosticPort>
246+
<DiagnosticSuspend Condition="'$(DiagnosticSuspend)' == ''">false</DiagnosticSuspend>
247+
<DiagnosticListenMode Condition="'$(DiagnosticListenMode)' == ''">listen</DiagnosticListenMode>
248+
<DiagnosticConfiguration>$(DiagnosticAddress):$(DiagnosticPort),$(DiagnosticListenMode)</DiagnosticConfiguration>
249+
<DiagnosticConfiguration Condition="'$(DiagnosticSuspend)' == 'true'">$(DiagnosticConfiguration),suspend</DiagnosticConfiguration>
250+
<DiagnosticConfiguration Condition="'$(DiagnosticSuspend)' != 'true'">$(DiagnosticConfiguration),nosuspend</DiagnosticConfiguration>
251+
</PropertyGroup>
252+
<PropertyGroup Condition="'$(EnableDiagnostics)' == 'true' And '$(DiagnosticConfiguration)' != '' And '$(DiagnosticConfiguration)' != 'disable'">
253+
<AppBundleExtraOptions>$(AppBundleExtraOptions) --setenv=DOTNET_DiagnosticPorts=$(DiagnosticConfiguration)</AppBundleExtraOptions>
241254
</PropertyGroup>
242255

243256
<PropertyGroup Condition="'$(IsBindingProject)' == 'true'">

0 commit comments

Comments
 (0)