Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Handling Multiple TargetFrameworks through BuildProperties #567

Merged
merged 44 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8dbb2a5
adding a sample project with plural form of TargetFrameworks for debu…
tebeco Jun 26, 2020
333e9cf
add --framework argument to RunCommand
tebeco Jun 27, 2020
d4cecb9
Pass down "framework" as a BuildProperty if not already defined in th…
tebeco Jun 27, 2020
2574622
Do no throw anymore when multiple TargetFrameworks are found, if one …
tebeco Jun 27, 2020
b0ff307
replicating Signature change on code base (that does not look like a …
tebeco Jun 27, 2020
48f42c6
adding comment to be explicit on what this does
tebeco Jun 27, 2020
889c15d
Check that the specified BuildProperties["TargetFramework"] is on of …
tebeco Jun 27, 2020
6ccf418
add launchSettings for debug
tebeco Jul 12, 2020
e5b00f5
Create a BuildCommandArguments for the BuildCommand / add a "framewor…
tebeco Jul 12, 2020
96ba02d
add "-f {framework}" to dotnet publish if a TargetFramework BuildProp…
tebeco Jul 12, 2020
a71d7b2
Create a GenerateCommandArguments for the GenerateCommand / add a "fr…
tebeco Jul 12, 2020
f6d6ad2
Create a PushCommandArguments for the PushCommand / add a "framework"…
tebeco Jul 12, 2020
7a370c1
Create a UndeployCommandArguments for the UndeployCommand / add a "fr…
tebeco Jul 12, 2020
365c95d
Create a DeployCommandArguments for the DeployCommand / add a "framew…
tebeco Jul 12, 2020
67c2eaa
framework is now an optional parameter defaulted to null
tebeco Jul 13, 2020
77f04bb
Change sample to use LTS only
tebeco Jul 13, 2020
29bf9b7
Make "framework" argument nullable / optional / defaulted to null
tebeco Jul 13, 2020
e4c0ba6
remove "Force" from "PushCommand" and "PushCommandArguments" if it's …
tebeco Jul 13, 2020
3d7ff54
re-use the equivalent message than "dotnet run" on a project with mul…
tebeco Jul 13, 2020
2fac5cd
Create a StandardOptions for Framework
tebeco Jul 13, 2020
1538fb7
Remove unused StandardOption.Force and add StandardOption.CreateForce…
tebeco Jul 14, 2020
1e5b2d7
Use StandardOptions.Framework in various commands
tebeco Jul 14, 2020
a082ff7
use StandardOptions.Force ni various commands
tebeco Jul 14, 2020
2d197c9
Create a new InitCommandArguments and re-use the same OutputContext l…
tebeco Jul 14, 2020
edaa741
prefer type alias (String.IsNullOrEmpty => string.IsNullOrEmpty), not…
tebeco Jul 14, 2020
e9f17b1
Adding assets for E2E about multi-targetframeworks that returns the c…
tebeco Jul 18, 2020
e81d15b
Adding test for "tye run" with either buildProperties in the yaml or …
tebeco Jul 18, 2020
9a9e9aa
Add test and testasset project for both TargetFrameworks and TargetFr…
tebeco Jul 18, 2020
f91deeb
Always overwrite the TargetFramework if one is specified from the CLI…
tebeco Jul 19, 2020
a8e6c8a
Test the ability to override TargetFramework from CLI even if define …
tebeco Jul 19, 2020
25f649b
Consistency over ApplicationFactory.CreateAsync in all E2E tests
tebeco Jul 19, 2020
18e1ec8
rename testasset project to multi-targetframeworks to match generated…
tebeco Jul 19, 2020
6efc117
Add E2E for tye build when project uses multi-targetframeworks
tebeco Jul 19, 2020
b1d4977
Adding test directly for ApplicationFactory to check that it override…
tebeco Jul 21, 2020
aceeba0
Adding test to make sure it still throw if there's no explicit Target…
tebeco Jul 21, 2020
d5a45e6
Adding test for ApplicationFactory.CreateAsync with a framework if no…
tebeco Jul 21, 2020
0773d99
make cli arguments class private
tebeco Sep 2, 2020
1761cfe
review: remove extra line
tebeco Sep 2, 2020
02f2565
review: remove 'framework' notion from Undeploy
tebeco Sep 15, 2020
56ab74e
Fix project evaluation of multi-targetd projects
Oct 21, 2020
031b646
Merge pull request #1 from dotnet/johluo/multi-tfm-fixup
tebeco Oct 21, 2020
1fff983
Fixup a few more tests
Oct 21, 2020
e632b84
Comment updates
Oct 22, 2020
e806436
Ensure TFM is only applied for multi-targeting projects
Oct 24, 2020
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
Prev Previous commit
Next Next commit
rename testasset project to multi-targetframeworks to match generated…
… Dockerfile
  • Loading branch information
tebeco committed Sep 30, 2020
commit 18e1ec831b5b8b9330f21163562eeb097ebda719
8 changes: 4 additions & 4 deletions test/E2ETest/TyeRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ public async Task RunExplicitYamlMultipleTargetFrameworksTest()
await RunHostingApplication(application, new HostOptions(), async (app, uri) =>
{
// make sure it is running
var backendUri = await GetServiceUrl(client, uri, "backend");
var backendUri = await GetServiceUrl(client, uri, "multi-targetframeworks");

var backendResponse = await client.GetAsync(backendUri);
Assert.True(backendResponse.IsSuccessStatusCode);
Expand Down Expand Up @@ -957,7 +957,7 @@ public async Task RunWithArgsMultipleTargetFrameworksTest()
await RunHostingApplication(application, new HostOptions(), async (app, uri) =>
{
// make sure it is running
var backendUri = await GetServiceUrl(client, uri, "backend");
var backendUri = await GetServiceUrl(client, uri, "multi-targetframeworks");

var backendResponse = await client.GetAsync(backendUri);
Assert.True(backendResponse.IsSuccessStatusCode);
Expand Down Expand Up @@ -988,7 +988,7 @@ public async Task RunCliArgOverrideYamlMultipleTargetFrameworksTest()
await RunHostingApplication(application, new HostOptions(), async (app, uri) =>
{
// make sure it is running
var backendUri = await GetServiceUrl(client, uri, "backend");
var backendUri = await GetServiceUrl(client, uri, "multi-targetframeworks");

var backendResponse = await client.GetAsync(backendUri);
Assert.True(backendResponse.IsSuccessStatusCode);
Expand Down Expand Up @@ -1019,7 +1019,7 @@ public async Task RunIgnorePluralTargetFrameworksWhenSingularFormExistsTest()
await RunHostingApplication(application, new HostOptions(), async (app, uri) =>
{
// make sure it is running
var backendUri = await GetServiceUrl(client, uri, "backend");
var backendUri = await GetServiceUrl(client, uri, "multi-targetframeworks-and-targetframework-too");

var backendResponse = await client.GetAsync(backendUri);
Assert.True(backendResponse.IsSuccessStatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "backend", "backend\backend.csproj", "{CA427ACE-098F-4883-8A91-02F766FC2D46}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "multi-targetframeworks-and-targetframework-too", "multi-targetframeworks-and-targetframework-too\multi-targetframeworks-and-targetframework-too.csproj", "{CA427ACE-098F-4883-8A91-02F766FC2D46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.AspNetCore;
#endif

namespace Backend
namespace MultiTargetFrameworks
{
public class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection;
using System.Runtime.Versioning;

namespace Backend
namespace MultiTargetFrameworks
{
public class Startup
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

Choose a reason for hiding this comment

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

projects shouldn't specify both TargetFramework and TargetFrameworks at the same time. I don't think testing such a scenario is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand it's weird to read, this is how MsBuild and dotnet works today
So I tried to cover existing "possible scenario"
This is also how dotnet/tye works in tye.yaml when using buildProperties for TargetFramework if the csproj uses TargetFrameworks
What should I do ? Do you want me to remove this sample anyway ?

eg:
image

Copy link

@JunTaoLuo JunTaoLuo Sep 2, 2020

Choose a reason for hiding this comment

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

So yes and no, for example take a look at the docs https://docs.microsoft.com/en-us/dotnet/standard/frameworks#how-to-specify-target-frameworks. The idea is that you can target multiple frameworks in your project by using TargetFrameworks. This is especially important for libraries which might need to maintain compatibility with older frameworks but also take advantage of new APIs but can also be done for apps like you've demonstrated. However, if you do multi-target apps you are essentially building for both TFMs and you will need to specify a specific target framework to run. The mechanism to do this is to specify a single TargetFramework, for example via CLI. However, it doesn't make sense to do so in a csproj file since if you are specifying a single TargetFramework at build time, why even bother defining multiple frameworks in the first place?

Unless there's a compelling reason to keep this sample, I would remove it and the tests associated with it.

Copy link
Contributor Author

@tebeco tebeco Sep 2, 2020

Choose a reason for hiding this comment

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

sorry, as I tried to read your comments here, I know realize that my answer is split in two with
#567 (comment)

Also this is also practical aside library, especially when you are migrating a webapi or a CLI from netcoreapp3.1 to net5.0 for example. It allows you to have both code build / test / E2E and decide within the CI or deployement which artifact you will ship to production (or even both for canary or blue/green)

Of course the --framework is, defacto, mandatory for such use, but it's not limited to library. I did not tried to overthink it to be fair, I just tried to make sure the behavior of tye was somehow the same as dotnet.
I'm fine with keeping or removing it, but I guess this will depends on the other comment bellow

Copy link

@JunTaoLuo JunTaoLuo Sep 2, 2020

Choose a reason for hiding this comment

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

As I said previously,

but can also be done for apps like you've demonstrated

I'm agreeing with you that there is valid use of multi-targeted apps. The comment about libraries is more of a side note. My main point is that it doesn't make sense to specify both TargetFramework and TargetFrameworks in an app. You either specify one or the other.

Choose a reason for hiding this comment

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

Just to circle back, the TargetFramework property should be removed here.

<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Backend</RootNamespace>
<RootNamespace>MultiTargetFrameworks</RootNamespace>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# tye application configuration file
# read all about it at https://github.com/dotnet/tye
name: multi-targetframeworks
name: multi-targetframeworks-and-targetframework-too
services:
- name: backend
project: backend/backend.csproj
- name: multi-targetframeworks-and-targetframework-too
project: multi-targetframeworks-and-targetframework-too/multi-targetframeworks-and-targetframework-too.csproj
bindings:
- port: 7000
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "backend", "backend\backend.csproj", "{CA427ACE-098F-4883-8A91-02F766FC2D46}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "multi-targetframeworks", "multi-targetframeworks\multi-targetframeworks.csproj", "{CA427ACE-098F-4883-8A91-02F766FC2D46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.AspNetCore;
#endif

namespace Backend
namespace MultiTargetFrameworks
{
public class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"backend": {
"multi-targetframeworks": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection;
using System.Runtime.Versioning;

namespace Backend
namespace MultiTargetFrameworks
{
public class Startup
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Backend</RootNamespace>
<RootNamespace>MultiTargetFrameworks</RootNamespace>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# read all about it at https://github.com/dotnet/tye
name: multi-targetframeworks
services:
- name: backend
project: backend/backend.csproj
- name: multi-targetframeworks
project: multi-targetframeworks/multi-targetframeworks.csproj
bindings:
- port: 7000
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# read all about it at https://github.com/dotnet/tye
name: multi-targetframeworks
services:
- name: backend
project: backend/backend.csproj
- name: multi-targetframeworks
project: multi-targetframeworks/multi-targetframeworks.csproj
buildProperties:
- name: TargetFramework
value: netcoreapp2.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# read all about it at https://github.com/dotnet/tye
name: multi-targetframeworks
services:
- name: backend
project: backend/backend.csproj
- name: multi-targetframeworks
project: multi-targetframeworks/multi-targetframeworks.csproj
buildProperties:
- name: TargetFramework
value: netcoreapp3.1
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy