Skip to content

Commit

Permalink
Allow using VS to run host tests when libraries use different config (d…
Browse files Browse the repository at this point in the history
…otnet#91873)

* Allow using VS to run host tests when libraries use different config

When building the host tests from VS, there are dependencies on projects from the libraries subset. If the libraries are prebuilt with different configuration (typically `Release`) the build in VS breaks because it can't find the project's output.

This change modifies the import of generators (which are the problematic projects) to let them override the configuration of the referenced projects.

It then adds the ability to set environment based on the `-lc` parameter to the build script when starting VS.

Also updates the doc to describe how to use this.

* Update eng/build.ps1

Co-authored-by: Elinor Fung <[email protected]>

* Update eng/generators.targets

* Move ShouldUnsetParentConfigurationAndPlatform to repo's Directory.Build.props

---------

Co-authored-by: Elinor Fung <[email protected]>
  • Loading branch information
vitek-karas and elinor-fung authored Mar 13, 2024
1 parent cb7154d commit 578e829
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
all cases, rather than ordinarily where we build them during mobile or wasm
build legs. This makes the manifests available on source-only builds. -->
<ForceBuildMobileManifests Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</ForceBuildMobileManifests>
<!-- Propagate the configuration and platform to project references. When building in VS, this defaults to true.
Explicitly setting it to false ensures projects are built in the corresponding configuration both in VS and on the command line. -->
<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
</PropertyGroup>

<PropertyGroup Label="CalculateTargetOS">
Expand Down
5 changes: 5 additions & 0 deletions docs/workflow/testing/host/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ The `category!=failing` is to respect the [filtering traits](../libraries/filter
### Visual Studio
The [Microsoft.DotNet.CoreSetup.sln](/src/installer/Microsoft.DotNet.CoreSetup.sln) can be used to run and debug host tests through Visual Studio. When using the solution, the product should have already been [built](#building-tests) and the [test context](#test-context) set up.
If you built the runtime or libraries with a different configuration from the host, you have to specify this when starting visual studio:
```console
build.cmd -vs Microsoft.DotNet.CoreSetup -rc Release -lc Release
```

### Preserving test artifacts

Expand Down
6 changes: 6 additions & 0 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ if ($vs) {
$env:RUNTIMECONFIGURATION=$runtimeConfiguration
}

if ($librariesConfiguration)
{
# Respect the LibrariesConfiguration variable for building inside VS with different libraries configurations
$env:LIBRARIESCONFIGURATION=$librariesConfiguration
}

# Respect the RuntimeFlavor variable for building inside VS with a different CoreLib and runtime
if ($runtimeFlavor)
{
Expand Down
1 change: 0 additions & 1 deletion src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<PropertyGroup>
<BeforeTargetFrameworkInferenceTargets>$(RepositoryEngineeringDir)BeforeTargetFrameworkInference.targets</BeforeTargetFrameworkInferenceTargets>
<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
<GeneratePlatformNotSupportedAssemblyHeaderFile>$(RepositoryEngineeringDir)LicenseHeader.txt</GeneratePlatformNotSupportedAssemblyHeaderFile>
</PropertyGroup>

Expand Down

0 comments on commit 578e829

Please sign in to comment.