From 1571643ded3ed9118620ce954016189a07ac9812 Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Fri, 5 Feb 2021 09:03:29 -0800 Subject: [PATCH] Revert 'Opt into IncludePackageReferencesDuringMarkupCompilation' --- .../Microsoft.NET.Sdk.BeforeCommon.targets | 1 - ...ThatWeWantToBuildAWindowsDesktopProject.cs | 90 ------------------- 2 files changed, 91 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index a036e2fe5ff1..0626e0520143 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -23,7 +23,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_IsExecutable Condition="'$(OutputType)' == 'Exe' or '$(OutputType)'=='WinExe'">true WinExe - true diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs index 50ee22d85a07..807a84549c36 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs @@ -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, $@" - - WinExe - net5.0-windows - true - preview - - - - -".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 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('`', '"'); } }