Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Source Link's EmbedUntrackedSources in desktop WPF projects #37164

Merged
merged 6 commits into from
Dec 7, 2023
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
10 changes: 10 additions & 0 deletions src/Assets/TestProjects/DesktopWpf/FxWpf/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
20 changes: 20 additions & 0 deletions src/Assets/TestProjects/DesktopWpf/FxWpf/FxWpf.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net472</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<IntermediateOutputPath>$(MSBuildThisFileDirectory)\..\obj\</IntermediateOutputPath>
</PropertyGroup>

<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
<Reference Include="System.Xaml" />

<Page Include="MainWindow.xaml" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions src/Assets/TestProjects/DesktopWpf/FxWpf/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Window x:Class="FxWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FxWpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>

</Grid>
</Window>
23 changes: 23 additions & 0 deletions src/Assets/TestProjects/DesktopWpf/FxWpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FxWpf;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
// InitializeComponent();
}
}
13 changes: 13 additions & 0 deletions src/Assets/TestProjects/DesktopWpf/FxWpf/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Windows;

class C
{
[STAThread]
static void Main(string[] args)
{
var app = new Application();
var window = new Window();
app.Run(window);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<_SourceLinkSdkSubDir>build</_SourceLinkSdkSubDir>
<_SourceLinkSdkSubDir Condition="'$(IsCrossTargetingBuild)' == 'true'">buildMultiTargeting</_SourceLinkSdkSubDir>

<EmbedUntrackedSources Condition="'$(EmbedUntrackedSources)' == ''">true</EmbedUntrackedSources>
<!-- Workaround for https://github.com/dotnet/sdk/issues/36585 (Desktop XAML targets do not produce correct #line directives) -->
<EmbedUntrackedSources Condition="'$(EmbedUntrackedSources)' == '' and '$(ImportFrameworkWinFXTargets)' != 'true'">true</EmbedUntrackedSources>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Microsoft.Build.Tasks.Git\build\Microsoft.Build.Tasks.Git.targets"/>
Expand Down
29 changes: 26 additions & 3 deletions src/Tests/Microsoft.NET.Build.Tests/SourceLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ public void Cpp()
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
.WithSource();

testAsset = WithProperties(testAsset, ("EnableManagedPackageReferenceSupport", "true"));
var intDir = Path.Combine(testAsset.Path, "NETCoreCppCliTest", "IntDir");

testAsset = WithProperties(testAsset,
("EnableManagedPackageReferenceSupport", "true"),
("IntermediateOutputPath", intDir));

CreateGitFiles(testAsset.Path, "https://github.com/org/repo");

Expand All @@ -306,15 +310,34 @@ public void Cpp()

buildCommand.Execute("-p:Platform=x64").Should().Pass();

var outputDir = Path.Combine(testAsset.Path, "NETCoreCppCliTest", "x64", "Debug");
var sourceLinkFilePath = Path.Combine(outputDir, "NETCoreCppCliTest.sourcelink.json");
var sourceLinkFilePath = Path.Combine(intDir, "NETCoreCppCliTest.sourcelink.json");
var actualContent = File.ReadAllText(sourceLinkFilePath, Encoding.UTF8);
var expectedPattern = Path.Combine(testAsset.Path, "*").Replace("\\", "\\\\");
var expectedSourceLink = $$$"""{"documents":{"{{{expectedPattern}}}":"https://raw.githubusercontent.com/org/repo/1200000000000000000000000000000000000000/*"}}""";
Assert.Equal(expectedSourceLink, actualContent);

var outputDir = Path.Combine(testAsset.Path, "NETCoreCppCliTest", "x64", "Debug");
var pdbText = File.ReadAllText(Path.Combine(outputDir, "NETCoreCppCliTest.pdb"), Encoding.UTF8);
Assert.Contains(expectedSourceLink, pdbText);
}

[FullMSBuildOnlyFact]
public void LegacyDesktopWpf()
{
var testAsset = _testAssetsManager
.CopyTestAsset("DesktopWpf")
.WithSource();

CreateGitFiles(testAsset.Path, "https://github.com/org/repo");

var buildCommand = new BuildCommand(testAsset, relativePathToProject: "FxWpf")
{
WorkingDirectory = Path.Combine(testAsset.Path, "FxWpf")
};

buildCommand.Execute().Should().Pass();

Assert.True(File.Exists(Path.Combine(testAsset.Path, "obj", "net472", "MainWindow.g.cs")));
}
}
}