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

Revert 'Opt into IncludePackageReferencesDuringMarkupCompilation' #15790

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup>
<_IsExecutable Condition="'$(OutputType)' == 'Exe' or '$(OutputType)'=='WinExe'">true</_IsExecutable>
<OutputType Condition="'$(DisableWinExeOutputInference)' != 'true' and '$(OutputType)' == 'Exe' and ('$(UseWindowsForms)' == 'true' or '$(UseWPF)' == 'true')">WinExe</OutputType>
<IncludePackageReferencesDuringMarkupCompilation Condition=" '$(IncludePackageReferencesDuringMarkupCompilation)' == '' ">true</IncludePackageReferencesDuringMarkupCompilation>
</PropertyGroup>

<PropertyGroup Condition="'$(HasRuntimeOutput)' == ''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,95 +351,5 @@ private string GetPropertyValue(TestAsset testAsset, string propertyName)

return getValueCommand.GetValues().Single();
}

[WindowsOnlyFact]
public void It_can_use_source_generators_with_wpf()
{
var sourceGenProject = new TestProject()
{
Name = "SourceGen",
TargetFrameworks = "netstandard2.0"
};
sourceGenProject.AdditionalProperties.Add("LangVersion", "preview");
sourceGenProject.PackageReferences.Add(new TestPackageReference("Microsoft.CodeAnalysis.CSharp", "3.8.0-3.final", privateAssets: "all"));
sourceGenProject.PackageReferences.Add(new TestPackageReference("Microsoft.CodeAnalysis.Analyzers", "3.0.0", privateAssets: "all"));
sourceGenProject.SourceFiles.Add("Program.cs", SourceGenSourceFile);
var sourceGenTestAsset = _testAssetsManager.CreateTestProject(sourceGenProject);

var testDir = sourceGenTestAsset.Path;
var newCommand = new DotnetCommand(Log, "new", "wpf", "-o", "wpfApp", "--no-restore");
newCommand.WorkingDirectory = testDir;
newCommand.Execute()
.Should()
.Pass();

// Reference generated code from a wpf app
var projFile = Path.Combine(testDir, "wpfApp", "wpfApp.csproj");
File.WriteAllText(projFile, $@"<Project Sdk=`Microsoft.NET.Sdk`>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include=`..\{sourceGenProject.Name}\{sourceGenProject.Name}.csproj` OutputItemType=`Analyzer` ReferenceOutputAssembly=`false` />
</ItemGroup>
</Project>".Replace('`', '"'));
File.WriteAllText(Path.Combine(testDir, "wpfApp", "MainWindow.xaml.cs"), $@"using System.Windows;
namespace wpfApp
{{
public partial class MainWindow : Window
{{
public MainWindow()
{{
HelloWorldGenerated.HelloWorld.SayHello();
}}
}}
}}");

var buildCommand = new BuildCommand(Log, Path.Combine(testDir, "wpfApp"));
buildCommand.Execute()
.Should()
.Pass();
}

private static readonly string SourceGenSourceFile = @"using System.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;

namespace SourceGeneratorSamples
{
[Generator]
public class HelloWorldGenerator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
StringBuilder sourceBuilder = new StringBuilder(@`
using System;
namespace HelloWorldGenerated
{
public static class HelloWorld
{
public static void SayHello()
{
Console.WriteLine(``Hello from generated code!``);
`);
IEnumerable<SyntaxTree> syntaxTrees = context.Compilation.SyntaxTrees;
foreach (SyntaxTree tree in syntaxTrees)
{
sourceBuilder.AppendLine($@`Console.WriteLine(@`` - {tree.FilePath}``);`);
}
sourceBuilder.Append(@`
}
}
}`);
context.AddSource(`helloWorldGenerated`, SourceText.From(sourceBuilder.ToString(), Encoding.UTF8));
}

public void Initialize(GeneratorInitializationContext context) {}
}
}".Replace('`', '"');
}
}