Skip to content

Commit

Permalink
Fix building of csproj samples directly (#1168)
Browse files Browse the repository at this point in the history
* Fix building of csproj samples directly

* - continue to build sln

* - catalyst
  • Loading branch information
PureWeen authored Jun 4, 2021
1 parent ae93d62 commit 2e71365
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
3 changes: 1 addition & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
<Import Project="eng\Versions.props" />

<PropertyGroup>

<BuildForWinUI Condition="'$(SolutionFileName)' == 'Microsoft.Maui.WinUI.sln' AND '$(Packing)' == ''">true</BuildForWinUI>
<BuildForAndroid Condition="'$(SolutionFileName)' == 'Microsoft.Maui.Droid.sln' AND '$(Packing)' == ''">true</BuildForAndroid>
<BuildForNet6 Condition="'$(Packing)' == 'true' OR $(SolutionFileName.Contains('net6')) == true OR '$(BuildForWinUI)' == 'true' OR '$(BuildForAndroid)' == 'true'">true</BuildForNet6>
<BuildForNet6 Condition="'$(Packing)' == 'true' OR $(MSBuildProjectFile.Contains('SingleProject')) == true OR $(MSBuildProjectFile.Contains('net6')) == true OR $(SolutionFileName.Contains('net6')) == true OR '$(BuildForWinUI)' == 'true' OR '$(BuildForAndroid)' == 'true'">true</BuildForNet6>
<MauiPlatforms>net6.0-ios;net6.0-maccatalyst;net6.0-android</MauiPlatforms>
<WindowsTargetFramework Condition="'$(WindowsTargetFramework)' == ''">net6.0-windows10.0.18362</WindowsTargetFramework>
<MauiPlatforms Condition="'$(Packing)' == 'true'">$(MauiPlatforms);$(WindowsTargetFramework)</MauiPlatforms>
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@

- Install the SDKs listed here https://github.com/dotnet/maui-samples

- And/or run the following

```
dotnet tool install Cake.Tool -g
```

### Running

#### IDE
Expand All @@ -39,12 +33,17 @@ dotnet tool install Cake.Tool -g
You can run a `Cake` target to bootstrap .NET 6 in `bin\dotnet` and launch Visual Studio:

```dotnetcli
dotnet tool restore
dotnet cake --target=VS-NET6
```
_NOTE: VS Mac is not yet supported._
_NOTES:_
- _VS Mac is not yet supported._
- _If the IDE doesn't show any android devices try unloading and reloading the `Sample.Droid-net6` project._

You can also run commands individually:
```dotnetcli
# install local tools required to build (cake, pwsh, etc..)
dotnet tool restore
# Provision .NET 6 in bin\dotnet
dotnet build src\DotNet\DotNet.csproj
# Builds Maui MSBuild tasks
Expand Down
33 changes: 31 additions & 2 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ Task("VS-ANDROID")
StartVisualStudioForDotNet6("./Microsoft.Maui.Droid.sln");
});

Task("SAMPLE-ANDROID")
.Description("Provisions .NET 6 and launches Android Sample.")
.IsDependentOn("dotnet")
.IsDependentOn("dotnet-buildtasks")
.Does(() =>
{
RunMSBuildWithLocalDotNet("./src/Controls/samples/Controls.Sample.Droid/Maui.Controls.Sample.Droid-net6.csproj", deployAndRun:true);
});

Task("SAMPLE-IOS")
.Description("Provisions .NET 6 and launches launches iOS Sample.")
.IsDependentOn("dotnet")
.IsDependentOn("dotnet-buildtasks")
.Does(() =>
{
RunMSBuildWithLocalDotNet("./src/Controls/samples/Controls.Sample.iOS/Maui.Controls.Sample.iOS-net6.csproj", deployAndRun:true);
});

Task("SAMPLE-MAC")
.Description("Provisions .NET 6 and launches Mac Catalyst Sample.")
.IsDependentOn("dotnet")
.IsDependentOn("dotnet-buildtasks")
.Does(() =>
{
RunMSBuildWithLocalDotNet("./src/Controls/samples/Controls.Sample.MacCatalyst/Maui.Controls.Sample.MacCatalyst-net6.csproj", deployAndRun:true);
});


string FindMSBuild()
{
if (IsRunningOnWindows())
Expand Down Expand Up @@ -213,15 +241,15 @@ void StartVisualStudioForDotNet6(string sln = "./Microsoft.Maui-net6.sln")
}

// NOTE: this method works as long as the DotNet target has already run
void RunMSBuildWithLocalDotNet(string sln, Action<object> settings = null)
void RunMSBuildWithLocalDotNet(string sln, Action<object> settings = null, bool deployAndRun = false)
{
var name = System.IO.Path.GetFileNameWithoutExtension(sln);
var binlog = $"artifacts/{name}-{configuration}.binlog";

SetDotNetEnvironmentVariables();

// If we're not on Windows, use ./bin/dotnet/dotnet
if (!IsRunningOnWindows())
if (!IsRunningOnWindows() || deployAndRun)
{
var dotnetBuildSettings = new DotNetCoreMSBuildSettings
{
Expand All @@ -240,6 +268,7 @@ void RunMSBuildWithLocalDotNet(string sln, Action<object> settings = null)
Configuration = configuration,
ToolPath = dotnetPath,
MSBuildSettings = dotnetBuildSettings,
ArgumentCustomization = args=> { if(deployAndRun) { args.Append("-t:Run"); } return args; }
});
return;
}
Expand Down
4 changes: 4 additions & 0 deletions eng/pipelines/handlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ stages:
& dotnet build src/DotNet/DotNet.csproj -bl:$(LogDirectory)/$(BuildConfiguration)-dotnet.binlog
$env:PATH = (Join-Path '$(System.DefaultWorkingDirectory)' 'bin/dotnet') + [IO.Path]::PathSeparator + $env:PATH
& $(DotNet.Path) build Microsoft.Maui.BuildTasks-net6.sln -c $(BuildConfiguration) -bl:$(LogDirectory)/$(BuildConfiguration)-buildtasks.binlog
& $(DotNet.Path) build src/Controls/samples/Controls.Sample.Droid/Maui.Controls.Sample.Droid-net6.csproj -c $(BuildConfiguration) -bl:$(LogDirectory)/$(BuildConfiguration)-android.binlog
& $(DotNet.Path) build src/Controls/samples/Controls.Sample.iOS/Maui.Controls.Sample.iOS-net6.csproj -c $(BuildConfiguration) -bl:$(LogDirectory)/$(BuildConfiguration)-iOS.binlog
& $(DotNet.Path) build src/Controls/samples/Controls.Sample.MacCatalyst/Maui.Controls.Sample.MacCatalyst-net6.csproj -c $(BuildConfiguration) -bl:$(LogDirectory)/$(BuildConfiguration)-MacCatalyst.binlog
& $(DotNet.Path) build src/Controls/samples/Controls.Sample.SingleProject/Maui.Controls.Sample.SingleProject.csproj -c $(BuildConfiguration) -bl:$(LogDirectory)/$(BuildConfiguration)-SingleProject.binlog
& $(DotNet.Path) build Microsoft.Maui-net6.sln -c $(BuildConfiguration) -bl:$(LogDirectory)/$(BuildConfiguration).binlog
displayName: build samples
errorActionPreference: stop
Expand Down

0 comments on commit 2e71365

Please sign in to comment.