Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.
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
2 changes: 0 additions & 2 deletions src/Moq/Moq.Sdk.Tests/Moq.Sdk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

<!-- Don't include this assembly in the generated ReferencePaths.g.cs because we confuse Roslyn with NS2 + net471 refs -->
<IncludeTargetPath>false</IncludeTargetPath>
<!-- We declare the Analyzer to be a dependency for IDE build order -->
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<GlobalPackageReference Include="GitInfo" Version="2.0.11" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-*" Condition="Exists('..\..\.git')" />
<GlobalPackageReference Include="MSBuilder.GenerateAssemblyInfo" Version="0.2.1" />
<GlobalPackageReference Include="MSBuilder.ThisAssembly.Metadata" Version="0.1.3" />
<GlobalPackageReference Include="MSBuilder.ThisAssembly.Metadata" Version="0.1.4" />
<GlobalPackageReference Include="NuGet.Build.Packaging" Version="0.2.5-dev.*" />
<GlobalPackageReference Include="netfx-System.StringResources" Version="3.1.8" />
<GlobalPackageReference Include="IFluentInterface" Version="2.0.4" Condition="'$(Language)' == 'C#'" />
Expand All @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Update="Microsoft.Build" Version="15.7.179" />
<PackageReference Update="Microsoft.Build.Tasks.Core" Version="15.7.179" />
<PackageReference Update="Microsoft.Build.Locator" Version="1.0.18" />

<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Features" Version="2.9.0" />
<PackageReference Update="Microsoft.CodeAnalysis.VisualBasic.Features" Version="2.9.0" />
Expand Down
3 changes: 3 additions & 0 deletions src/Stunts/Stunts.Internal/DocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public static async Task<Document> ApplyCodeFixAsync(this Document document, str
ApplyChangesOperation operation;
if ((operation = operations.OfType<ApplyChangesOperation>().FirstOrDefault()) != null)
{
// According to https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/935 and
// https://github.com/dotnet/roslyn-sdk/issues/140, Sam Harwell mentioned that we should
// be forcing a re-parse of the document syntax tree at this point.
document = await operation.ChangedSolution.GetDocument(document.Id).RecreateDocumentAsync(cancellationToken);
// Retrieve the codefixes for the updated doc again.
codeFixes = await GetCodeFixes(document, codeFixName, analyzers, cancellationToken).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/MockBuildEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// Fake build engine for unit testing Tasks without spinning up
/// MSBuild.
/// </summary>
public class MockBuildEngine : IBuildEngine
class MockBuildEngine : IBuildEngine
{
bool trace = false;
ITestOutputHelper output;
Expand Down
29 changes: 29 additions & 0 deletions src/Testing/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Linq;
/// <summary>
/// Used by the InjectModuleInitializer. All code inside the Run method is ran as soon as the assembly is loaded.
/// </summary>
internal static partial class ModuleInitializer
{
/// <summary>
/// Initializes the module.
/// </summary>
internal static void Run()
{
if (!AppDomain.CurrentDomain.GetAssemblies().Any(x => x.GetName().Name == "Microsoft.Build"))
{
#pragma warning disable 0436
Microsoft.Build.Locator.MSBuildLocator.RegisterMSBuildPath(ThisAssembly.Metadata.MSBuildBinPath);
Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", ThisAssembly.Metadata.MSBuildBinPath, EnvironmentVariableTarget.Process);
#pragma warning restore 0436
}

OnRun();
}

/// <summary>
/// Declare in another partial class to extend what is run when the assembly is
/// loaded.
/// </summary>
static partial void OnRun();
}
1 change: 1 addition & 0 deletions src/Testing/Moq.Testing.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AssertCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MockBuildEngine.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ModuleInitializer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RecordingBehavior.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestOutputLogger.cs" />
Expand Down
14 changes: 3 additions & 11 deletions src/Testing/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static ProjectInfo CreateProjectInfo(string language, string assemblyName
(ParseOptions)new VisualBasicParseOptions(Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.Latest);

//The location of the .NET assemblies
var frameworkPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
var netstandardPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".nuget\packages\NETStandard.Library\2.0.0\build\netstandard2.0\ref");
if (!Directory.Exists(netstandardPath))
netstandardPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\ref");
Expand All @@ -45,17 +44,10 @@ public static ProjectInfo CreateProjectInfo(string language, string assemblyName
throw new InvalidOperationException("Failed to find location of .NETStandard 2.0 reference assemblies");

var referencePaths =
//new[]
//{
// typeof(object).Assembly.Location,
// typeof(Enumerable).Assembly.Location,
// typeof(CSharpCompilation).Assembly.Location,
// typeof(Compilation).Assembly.Location,
//}
Directory.EnumerateFiles(netstandardPath, "*.dll")
.Concat(ReferencePaths.Paths)
//ReferencePaths.Paths
//.Concat(Directory.EnumerateFiles(netstandardPath, "*.dll"))
#pragma warning disable CS0436 // Type conflicts with imported type
.Concat(ThisAssembly.Metadata.ReferencePaths.Split('|'))
#pragma warning restore CS0436 // Type conflicts with imported type
.Where(path => !string.IsNullOrEmpty(path) && File.Exists(path))
.Distinct(FileNameEqualityComparer.Default);

Expand Down
2 changes: 1 addition & 1 deletion src/Testing/TestOutputLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// <summary>
/// xunit logger > MSBuild logger
/// </summary>
public class TestOutputLogger : ILogger
class TestOutputLogger : ILogger
{
ITestOutputHelper output;

Expand Down
6 changes: 2 additions & 4 deletions src/build/PackageReferences.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
<PackageReference Include="xunit.runner.console" />
<!-- xunit.runner.console is used to implement /t:Test in test projects -->
<PackageReference Include="xunit.runner.msbuild" />

<!-- test projects need all of MSBuild assemblies in the output -->
<PackageReference Update="Microsoft.Build" ExcludeAssets="none" />
<PackageReference Update="Microsoft.Build.Tasks.Core" ExcludeAssets="none" />

<PackageReference Include="Microsoft.Build.Locator" />
</ItemGroup>

<Import Project="PackageReference.CopyLocal.targets" Condition="'$(EnforceCopyLocalAssets)' == 'true'" />
Expand Down
1 change: 0 additions & 1 deletion src/build/Settings.Tests.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project>

<PropertyGroup>
<OutputPath>$(OutputPath)UnitTests\$(MSBuildProjectName)\</OutputPath>
<NoWarn>1701;1702;1705;0436</NoWarn>

<CopyNuGetImplementations>true</CopyNuGetImplementations>
Expand Down
59 changes: 16 additions & 43 deletions src/build/Settings.Tests.targets
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<Project>
<PropertyGroup>
<ReferencePathsFile>$(IntermediateOutputPath)ReferencePaths.g.cs</ReferencePathsFile>
<CoreCompileDependsOn Condition="'$(Language)' == 'C#'">
$(CoreCompileDependsOn);
GenerateReferencePaths;
</CoreCompileDependsOn>
</PropertyGroup>

<ItemDefinitionGroup>
<ReferencePath>
Expand All @@ -14,6 +7,13 @@
</ReferencePath>
</ItemDefinitionGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadata">
<_Parameter1>MSBuildBinPath</_Parameter1>
<_Parameter2>$(MSBuildBinPath)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<Target Name="Test" DependsOnTargets="Build">
<xunit Assemblies="@(TargetPathWithTargetPlatformMoniker)" />
</Target>
Expand All @@ -28,49 +28,22 @@
<ExcludeReferenceFilter Include="Stunts\.Sdk" />
</ItemGroup>

<PropertyGroup>
<CoreCompileDependsOn>
$(CoreCompileDependsOn);
GenerateReferencePaths
</CoreCompileDependsOn>
</PropertyGroup>

<Target Name="GenerateReferencePaths"
Condition="'$(Language)' == 'C#'"
Inputs="$(MSBuildAllProjects)"
Outputs="$(ReferencePathsFile)"
DependsOnTargets="ResolveReferences">
<Target Name="AddReferencePathsMetadata" AfterTargets="ResolveReferences" BeforeTargets="GenerateThisAssemblyMetadata" DependsOnTargets="ResolveReferences;GetTargetPathWithTargetPlatformMoniker">

<FilterReferences References="@(ReferencePath)" Include="@(IncludeReferenceFilter)" Exclude="@(ExcludeReferenceFilter)">
<Output TaskParameter="Filtered" ItemName="_FilteredReferencePath" />
</FilterReferences>

<WriteLinesToFile File="$(ReferencePathsFile)"
Overwrite="true"
Lines='static class ReferencePaths
{
public static string[] Paths = new[]
{ '/>

<WriteLinesToFile File="$(ReferencePathsFile)"
Overwrite="false"
Lines='
@"%(_FilteredReferencePath.FullPath)",'/>

<WriteLinesToFile File="$(ReferencePathsFile)"
Condition="'$(IncludeTargetPath)' != 'false'"
Overwrite="false"
Lines='
@"$(TargetPath)",'/>

<WriteLinesToFile File="$(ReferencePathsFile)" Overwrite="false"
Lines='
}%3B
}'/>
<ItemGroup>
<_FilteredReferencePath Include="@(ReferencePath)" Condition="'%(ReferencePath.FrameworkFile)' == 'true'" />
<_FilteredReferencePath Include="@(TargetPathWithTargetPlatformMoniker)" />
</ItemGroup>

<ItemGroup>
<FileWrites Include="$(ReferencePathsFile)" />
<Compile Include="$(ReferencePathsFile)" />
<AssemblyAttribute Include="System.Reflection.AssemblyMetadata">
<_Parameter1>ReferencePaths</_Parameter1>
<_Parameter2>@(_FilteredReferencePath -> '%(FullPath)', '|')</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

</Target>
Expand Down