Skip to content

Commit

Permalink
isolate MSBuild, MSBuildExtensions, and Roslyn directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Jan 19, 2017
1 parent 6568113 commit b31b461
Show file tree
Hide file tree
Showing 40 changed files with 542 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

namespace Microsoft.DotNet.Cli.Utils
{
public static class ClassThatIsntInMicrosoftDotNetCliUtils
{
public static string GetValue() => "Hello there!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>Microsoft.DotNet.Cli.Utils</AssemblyName>
<Version>123.0.0.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>DependsOn.Other.Microsoft.DotNet.Cli.Utils</AssemblyName>
<PackageId>PackagedTaskWithCliDependencyConflict</PackageId>
<Version>1.0.0-preview</Version>
</PropertyGroup>

<ItemGroup>
<ProjectReference
Include="..\Other.Microsoft.DotNet.Cli.Utils\Other.Microsoft.DotNet.Cli.Utils.csproj"
TreatAsPackageReference="false" />
</ItemGroup>

<ItemGroup>
<None Include="build\PackagedTaskWithCliDependencyConflict.targets" />
</ItemGroup>

<ItemGroup>
<Content Include="build\*.targets">
<Pack>true</Pack>
<PackagePath>build\</PackagePath>
</Content>
<Content Include="..\Other.Microsoft.DotNet.Cli.Utils\bin\Debug\netcoreapp1.0\Microsoft.DotNet.Cli.Utils.dll">
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App"
Version="1.0.3" />
<PackageReference Include="Microsoft.Build.Framework"
Version="15.1.0-preview-000458-02" />
<PackageReference Include="Microsoft.Build.Utilities.Core"
Version="15.1.0-preview-000458-02" />
</ItemGroup>

<Target Name="PackNuspec" AfterTargets="Pack">
<Exec Command="dotnet nuget pack PackagedTaskWithCliDependencyConflict.nuspec" />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>PackagedTaskWithCliDependencyConflict</id>
<version>1.0.0-preview</version>
<authors>DependsOn.Other.Microsoft.DotNet.Cli.Utils</authors>
<owners>DependsOn.Other.Microsoft.DotNet.Cli.Utils</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<files>
<file src="bin/$configuration$/netcoreapp1.0/*.dll" target="lib" />
<file src="build/PackagedTaskWithCliDependencyConflict.targets" />
</files>
</metadata>
</package>


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Build.Framework;
using Microsoft.DotNet.Cli.Utils;

namespace TaskFoundOnlyInOneVersion.Task
{
public class TaskFoundOnlyInOneVersion : Microsoft.Build.Utilities.Task
{
[Output]
public string TaskOutput { get; private set; }

public override bool Execute()
{
TaskOutput = ClassThatIsntInMicrosoftDotNetCliUtils.GetValue();
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TaskFoundOnlyInOneVersion"
AssemblyFile="$(MSBuildThisFileDirectory)/../bin/Debug/netcoreapp1.0/DependsOn.Other.Microsoft.DotNet.Cli.Utils.dll" />

<PropertyGroup>
<ApplicationName>$(AssemblyName)</ApplicationName>
<ApplicationName Condition="'$(AssemblyName)' == ''">$(MsBuildProjectName)</ApplicationName>
</PropertyGroup>

<Target Name="TaskFoundOnlyInOneVersion">
<TaskFoundOnlyInOneVersion />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App"
Version="1.0.3" />
<PackageReference Include="PackagedTaskWithCliDependencyConflict"
Version="1.0.0-preview" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="test-packages" value="../../../artifacts/testpackages" />
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Here I am!");
}
}
42 changes: 29 additions & 13 deletions build/Microsoft.DotNet.Cli.Compile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<PropertyGroup>
<BinaryToCorehostifyRelDir>runtimes/any/native</BinaryToCorehostifyRelDir>
<MSBuildImportsDir>$(RepoRoot)/resources/MSBuildImports</MSBuildImportsDir>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -52,6 +51,16 @@
InitCrossgenProps;"
Inputs="%(Stage.Inputs)"
Outputs="%(StageDirectory)/sdk/$(SdkVersion)/dotnet.dll">

<!--<SetEnvVar Name="CscToolExe"
Value="" />
<SetEnvVar Name="MSBuildExtensionsPath"
Value="" />
<SetEnvVar Name="MSBuildSDKsPath"
Value="" />
<SetEnvVar Name="MSBuildToolsPath"
Value="" />-->

<PropertyGroup>
<DynamicLibPrefix Condition=" '$(OSName)' == 'win' "></DynamicLibPrefix>
<DynamicLibPrefix Condition=" '$(OSName)' != 'win' ">lib</DynamicLibPrefix>
Expand All @@ -67,9 +76,10 @@
<StageDirectory>%(Stage.StageDirectory)</StageDirectory>
<StageSymbolsDirectory>%(Stage.StageSymbolsDirectory)</StageSymbolsDirectory>
<SdkOutputDirectory>$(StageDirectory)/sdk/$(SdkVersion)</SdkOutputDirectory>
<MSBuildOutputDirectory>$(SdkOutputDirectory)/MSBuild</MSBuildOutputDirectory>
<BinaryToCorehostifyOutDir>$(SdkOutputDirectory)/$(BinaryToCorehostifyRelDir)</BinaryToCorehostifyOutDir>
<MSBuildTargetsDirectory>$(SdkOutputDirectory)/runtimes/any/native</MSBuildTargetsDirectory>

<SharedFrameworkNameVersionPath>$(StageDirectory)/shared/$(SharedFrameworkName)/$(SharedFrameworkVersion)</SharedFrameworkNameVersionPath>
</PropertyGroup>

Expand Down Expand Up @@ -98,26 +108,36 @@

<!-- Workaround for https://github.com/dotnet/sdk/issues/115 -->
<ItemGroup>
<HackFilesToCopy Include="$(NuGetPackagesDir)\microsoft.build.runtime\$(CLI_MSBuild_Version)\contentFiles\any\netcoreapp1.0\**;$(NuGetPackagesDir)\microsoft.codeanalysis.build.tasks\2.0.0-beta6-60922-08\contentFiles\any\any\**;$(NuGetPackagesDir)\microsoft.testplatform.cli\$(CLI_TestPlatform_Version)\contentFiles\any\any\**" />
<HackFilesToCopy Include="$(NuGetPackagesDir)\microsoft.testplatform.cli\15.0.0-preview-20161123-03\contentFiles\any\any\**" />
</ItemGroup>
<Copy SourceFiles="@(HackFilesToCopy)"
DestinationFiles="@(HackFilesToCopy->'$(SdkOutputDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />

<!-- Publish DotNet -->
<DotNetPublish ToolPath="%(Stage.DotnetDir)"
Output="$(SdkOutputDirectory)"
Configuration="$(Configuration)"
VersionSuffix="$(CommitCount)"
ProjectPath="$(SrcDirectory)/redist/redist.csproj"
MSBuildArgs="/p:GenerateRuntimeConfigurationFiles=true" />

<!-- Publish DotNet -->
<DotNetPublish ToolPath="%(Stage.DotnetDir)"
Output="$(SdkOutputDirectory)/Roslyn"
Output="$(MSBuildOutputDirectory)/Roslyn"
Configuration="$(Configuration)"
VersionSuffix="$(CommitCount)"
ProjectPath="$(SrcDirectory)/tool_roslyn/tool_roslyn.csproj" />

<DotNetPublish ToolPath="%(Stage.DotnetDir)"
Output="$(MSBuildOutputDirectory)"
Configuration="$(Configuration)"
VersionSuffix="$(CommitCount)"
ProjectPath="$(SrcDirectory)/tool_msbuild/tool_msbuild.csproj" />

<DotNetPublish ToolPath="%(Stage.DotnetDir)"
Output="$(SdkOutputDirectory)/MSBuildExtensions"
Configuration="$(Configuration)"
VersionSuffix="$(CommitCount)"
ProjectPath="$(SrcDirectory)/tool_msbuildextensions/tool_msbuildextensions.csproj" />

<!-- Corehostify Binaries -->
<ItemGroup Condition=" '$(OSName)' != 'win' ">
<SdkOutputChmodTargets Remove="*" />
Expand Down Expand Up @@ -171,17 +191,13 @@

<Copy SourceFiles="$(SharedFrameworkNameVersionPath)/$(HostPolicyBaseName)"
DestinationFiles="$(SdkOutputDirectory)/$(HostPolicyBaseName)" />

<!-- copy core sdk -->
<Copy SourceFiles="@(MSBuildImportsContent)"
DestinationFolder="$(SdkOutputDirectory)/%(RecursiveDir)" />


<!-- Crossgen the Shared Framework -->
<ItemGroup>
<SdkFiles Remove="*" />

<!-- Removing Full CLR built TestHost assemblies from getting Crossgen as it is throwing error -->
<SdkFilesExclude Include="$(SdkOutputDirectory)/TestHost*/**/*" />
<SdkFilesExclude Include="$(SdkOutputDirectory)/TestHost*/**/*;$(SdkOutputDirectory)/MSBuildExtensions/TestHost*/**/*;$(SdkOutputDirectory)/MSBuild/TestHost*/**/*" />
<SdkFiles Include="$(SdkOutputDirectory)/**/*" Exclude="@(SdkFilesExclude)" />
<SdkFilesWithPEMarker Remove="*" />
</ItemGroup>
Expand Down Expand Up @@ -283,4 +299,4 @@
Projects="@(TemplatesToBundle)">
</MSBuild>
</Target>
</Project>
</Project>
9 changes: 9 additions & 0 deletions build/Microsoft.DotNet.Cli.Prepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
<Target Name="InitializeCommonProps"
DependsOnTargets="BuildDotnetCliBuildFramework" >

<SetEnvVar Name="CscToolExe"
Value="" />
<SetEnvVar Name="MSBuildExtensionsPath"
Value="" />
<SetEnvVar Name="MSBuildSDKsPath"
Value="" />
<SetEnvVar Name="MSBuildToolsPath"
Value="" />

<!-- Current Runtime Information -->
<GetCurrentRuntimeInformation OverrideRid="$(OverrideRid)">
<Output TaskParameter="Rid" PropertyName="Rid" />
Expand Down
2 changes: 1 addition & 1 deletion build/Microsoft.DotNet.Cli.Test.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
TestProject=%(TestProjects.ProjectPath);
TestProjectName=%(TestProjects.OutputName);
TestResultXmlDir=$(TestResultXmlDir);
ToolPath=$(Stage0Directory);
ToolPath=$(Stage2Directory);
WorkingDirectory=%(TestProjects.ProjectDir)
</Properties>
</ProjectsToTest>
Expand Down
32 changes: 22 additions & 10 deletions build/test/RunTest.proj
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTarget="RunTest" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- workaround for https://github.com/Microsoft/msbuild/issues/885 -->
<!-- renaming the property because the original property is a global property and therefore
cannot be redefined at runtime. -->
<PropertyGroup>
<CLIBuildDllPath>$([MSBuild]::Unescape($(CLIBuildDll)))</CLIBuildDllPath>
</PropertyGroup>

<UsingTask TaskName="DotNetTest" AssemblyFile="$(CLIBuildDllPath)" />
<!-- workaround for https://github.com/Microsoft/msbuild/issues/885 -->
<!-- renaming the property because the original property is a global property and therefore
cannot be redefined at runtime. -->
<PropertyGroup>
<CLIBuildDllPath>$([MSBuild]::Unescape($(CLIBuildDll)))</CLIBuildDllPath>
</PropertyGroup>

<UsingTask TaskName="DotNetTest" AssemblyFile="$(CLIBuildDllPath)" />
<UsingTask TaskName="SetEnvVar" AssemblyFile="$(CLIBuildDll)" />

<Target Name="RunTest">

<SetEnvVar Name="CscToolExe"
Value="" />
<SetEnvVar Name="MSBuildExtensionsPath"
Value="" />
<SetEnvVar Name="MSBuildSDKsPath"
Value="" />
<SetEnvVar Name="MSBuildToolsPath"
Value="" />

<Message Text="AfterSetEnvVar MSBuildExtensionsPath: $(MSBuildExtensionsPath)" Importance="High" />

<DotNetTest EnvironmentVariables="$(EnvironmentVariables)"
ToolPath="$(ToolPath)"
Configuration="$(Configuration)"
NoBuild="True"
Logger="trx"
ProjectPath="$(TestProject)" />
</Target>
</Project>
</Project>
11 changes: 11 additions & 0 deletions build/test/TestPackageProjects.targets
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@
<Clean>True</Clean>
<Frameworks>netcoreapp1.0</Frameworks>
</BaseTestPackageProject>
<BaseTestPackageProject Include="TestAssets/TestPackages/PackagedTaskWithCliDependencyConflict">
<Name>PackagedTaskWithCliDependencyConflict</Name>
<ProjectName>PackagedTaskWithCliDependencyConflict.csproj</ProjectName>
<NuPkgName>PackagedTaskWithCliDependencyConflict</NuPkgName>
<IsTool>False</IsTool>
<IsApplicable>True</IsApplicable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>preview</VersionSuffix>
<Clean>True</Clean>
<Frameworks>netcoreapp1.0</Frameworks>
</BaseTestPackageProject>
<BaseTestPackageProject Include="TestAssets/TestPackages/ToolWithOutputName">
<Name>dotnet-tool-with-output-name</Name>
<ProjectName>ToolWithOutputName.csproj</ProjectName>
Expand Down
19 changes: 18 additions & 1 deletion build_projects/dotnet-cli-build/DotNetTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Microsoft.DotNet.Cli.Build
{
public class DotNetTest : DotNetTool
Expand Down Expand Up @@ -52,7 +54,7 @@ private string GetProjectPath()

return null;
}

private string GetNoBuild()
{
if (NoBuild)
Expand All @@ -62,5 +64,20 @@ private string GetNoBuild()

return null;
}

public override bool Execute()
{
// clear environment variables so that child processes will re-evaluate them as needed
Environment.SetEnvironmentVariable(
"MSBUILD_EXE_PATH", null);
Environment.SetEnvironmentVariable(
"MSBuildExtensionsPath", null);
Environment.SetEnvironmentVariable(
"MSBuildSDKsPath", null);
Environment.SetEnvironmentVariable(
"MSBuildToolsPath", null);

return base.Execute();
}
}
}
1 change: 0 additions & 1 deletion build_projects/dotnet-cli-build/SetEnvVar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class SetEnvVar : Task
[Required]
public string Name { get; set; }

[Required]
public string Value { get; set; }

public override bool Execute()
Expand Down
Loading

0 comments on commit b31b461

Please sign in to comment.