Skip to content

Commit 34babbf

Browse files
authored
Merge pull request #351 from nguerrera/outputpath
Unblock having non-anycpu configurations by always setting output path
2 parents b1a2909 + dc31c2b commit 34babbf

16 files changed

+271
-38
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace ConsoleApplication
4+
{
5+
public class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
Console.WriteLine("Hello World!");
10+
}
11+
}
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
3+
4+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" />
5+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" />
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>netcoreapp1.0</TargetFramework>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Compile Include="**\*.cs" />
14+
<EmbeddedResource Include="**\*.resx" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.NETCore.App">
19+
<Version>1.0.1</Version>
20+
</PackageReference>
21+
<PackageReference Include="Microsoft.NET.Sdk">
22+
<Version>0.0.0</Version>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<Target Name="CheckPlatform" BeforeTargets="Build">
27+
<Error Condition="'$(Platform)' != 'x64'" Text="This test project expects to be built via solution and have Platform=x64" />
28+
</Target>
29+
30+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
31+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio 15
3+
VisualStudioVersion = 15.0.25827.1
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "x64SolutionBuild", "x64SolutionBuild.csproj", "{544B615E-491F-4C80-9918-B10A6FB4B3CD}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|x64 = Debug|x64
10+
Release|x64 = Release|x64
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Debug|x64.ActiveCfg = Debug|x64
14+
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Debug|x64.Build.0 = Debug|x64
15+
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Release|x64.ActiveCfg = Release|Any CPU
16+
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Release|x64.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
EndGlobal

src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
<None Include="buildCrossTargeting\Microsoft.NET.Sdk.targets">
7272
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7373
</None>
74+
<None Include="build\Microsoft.NET.DefaultOutputPaths.targets">
75+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76+
</None>
7477
<None Include="build\Microsoft.NET.RuntimeIdentifierInference.targets">
7578
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7679
</None>
@@ -83,6 +86,9 @@
8386
<None Include="build\Microsoft.NET.GenerateAssemblyInfo.targets">
8487
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8588
</None>
89+
<None Include="build\Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets">
90+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
91+
</None>
8692
<None Include="build\Microsoft.NET.Sdk.VisualBasic.props">
8793
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8894
</None>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.NET.DefaultOutputPaths.targets
4+
5+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6+
created a backup copy. Incorrect changes to this file will make it
7+
impossible to load or build your projects from the command-line or the IDE.
8+
9+
Copyright (c) .NET Foundation. All rights reserved.
10+
***********************************************************************************************
11+
-->
12+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
13+
14+
<!--
15+
Apply the same default output paths as Microsoft.Common.targets now since we're running before them,
16+
but need to adjust them and/or make decisions in terms of them.
17+
18+
Also note that common targets only set a default OutputPath if neither configuration nor
19+
platform were set by the user. This was used to validate that a valid configuration is passed,
20+
assuming the convention maintained by VS that every Configuration|Platform combination had
21+
an explicit OutputPath. Since we now want to support leaner project files with less
22+
duplication and more automatic defaults, we always set a default OutputPath and can no
23+
longer depend on that convention for validation. Getting validation re-enabled with a
24+
different mechanism is tracked by https://github.com/dotnet/sdk/issues/350
25+
-->
26+
<PropertyGroup>
27+
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
28+
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
29+
<PlatformName Condition="'$(PlatformName)' == ''">$(Platform)</PlatformName>
30+
31+
<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">bin\</BaseOutputPath>
32+
<BaseOutputPath Condition="!HasTrailingSlash('$(BaseOutputPath)')">$(BaseOutputPath)\</BaseOutputPath>
33+
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseOutputPath)$(Configuration)\</OutputPath>
34+
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseOutputPath)$(PlatformName)\$(Configuration)\</OutputPath>
35+
<OutputPath Condition="!HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>
36+
37+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
38+
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
39+
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' == 'AnyCPU' ">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
40+
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' != 'AnyCPU' ">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
41+
<IntermediateOutputPath Condition="!HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)\</IntermediateOutputPath>
42+
</PropertyGroup>
43+
44+
<!-- Set the package output path (for nuget pack target) now, before the TargetFramework is appended -->
45+
<PropertyGroup>
46+
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(OutputPath)</PackageOutputPath>
47+
</PropertyGroup>
48+
49+
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,9 @@ Copyright (c) .NET Foundation. All rights reserved.
1111
-->
1212
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1313

14-
<!--
15-
Apply the same defaults as Microsoft.Common.targets now since we're running before them,
16-
but need to adjust them and/or make decisions in terms of them.
17-
-->
18-
<PropertyGroup>
19-
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
20-
<PlatformName Condition="'$(PlatformName)' == ''">$(Platform)</PlatformName>
21-
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
22-
<OutputPath Condition="'$(OutputPath)' != '' and !HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>
23-
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
24-
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
25-
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' == 'AnyCPU' ">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
26-
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' != 'AnyCPU' ">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
27-
</PropertyGroup>
28-
14+
<!-- Set default intermediate and output paths -->
15+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />
16+
2917
<!--
3018
Expand TargetFramework (if set) to TargetFrameworkIdentifier and TargetFrameworkVersion,
3119
and adjust intermediate and output paths to include it.
@@ -35,7 +23,7 @@ Copyright (c) .NET Foundation. All rights reserved.
3523

3624
<!--
3725
Use RuntimeIdentifier to determine PlatformTarget.
38-
Also, enforce that RuntimeIdentifier always be specified for .NETFramework executables.
26+
Also, enforce that RuntimeIdentifier is always specified for .NETFramework executables.
3927
-->
4028
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.RuntimeIdentifierInference.targets" />
4129

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets
4+
5+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6+
created a backup copy. Incorrect changes to this file will make it
7+
impossible to load or build your projects from the command-line or the IDE.
8+
9+
Copyright (c) .NET Foundation. All rights reserved.
10+
***********************************************************************************************
11+
-->
12+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
13+
14+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />
15+
16+
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.CSharp.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Copyright (c) .NET Foundation. All rights reserved.
1515
<WarningLevel>4</WarningLevel>
1616
<NoWarn>1701;1702;1705</NoWarn>
1717
</PropertyGroup>
18-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
1919
<DefineConstants>DEBUG;TRACE</DefineConstants>
2020
</PropertyGroup>
21-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
21+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
2222
<DefineConstants>TRACE</DefineConstants>
2323
</PropertyGroup>
2424

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.VisualBasic.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Copyright (c) .NET Foundation. All rights reserved.
1515
<VBRuntime>Embed</VBRuntime>
1616
</PropertyGroup>
1717

18-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
1919
<DefineDebug>true</DefineDebug>
2020
<DefineTrace>true</DefineTrace>
2121
</PropertyGroup>
22-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
2323
<DefineTrace>true</DefineTrace>
2424
</PropertyGroup>
2525

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.props

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ Copyright (c) .NET Foundation. All rights reserved.
1515
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
1616
</PropertyGroup>
1717

18+
<!-- Default configuration and platform to Debug|AnyCPU-->
19+
<PropertyGroup>
20+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
21+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
22+
</PropertyGroup>
23+
24+
<!--
25+
Ensure VS sees two default configurations: Debug|AnyCPU and Release|AnyCPU
26+
27+
This is temproary until we have designed and implemented a new configuration management scheme,
28+
which is tracked by https://github.com/dotnet/sdk/issues/350. In the meantime, one consequence of
29+
defining these defaults here with the old inference-from-usage scheme here is that the user cannot
30+
remove or rename them.
31+
-->
32+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "/>
33+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "/>
34+
1835
<!-- User-facing configuration-agnostic defaults -->
1936
<PropertyGroup>
2037
<OutputType>Library</OutputType>
21-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
22-
<Platform>AnyCPU</Platform>
2338
<FileAlignment>512</FileAlignment>
2439
<ErrorReport>prompt</ErrorReport>
2540
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
@@ -28,14 +43,19 @@ Copyright (c) .NET Foundation. All rights reserved.
2843
</PropertyGroup>
2944

3045
<!-- User-facing configuration-specific defaults -->
31-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
46+
47+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
3248
<DebugSymbols>true</DebugSymbols>
3349
<Optimize>false</Optimize>
34-
<OutputPath>bin\Debug\</OutputPath>
3550
</PropertyGroup>
36-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
51+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3752
<Optimize>true</Optimize>
38-
<OutputPath>bin\Release\</OutputPath>
53+
</PropertyGroup>
54+
<PropertyGroup Condition=" '$(Platform)' == 'x64' ">
55+
<PlatformTarget>x64</PlatformTarget>
56+
</PropertyGroup>
57+
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
58+
<PlatformTarget>x86</PlatformTarget>
3959
</PropertyGroup>
4060

4161
<!-- Default settings for all projects built with this Sdk package -->
@@ -60,6 +80,7 @@ Copyright (c) .NET Foundation. All rights reserved.
6080

6181
<!-- Workaround: https://github.com/Microsoft/msbuild/issues/1045: This is the only before common targets hook available to us, but using it is hijacking a hook that should belong to the user. -->
6282
<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.BeforeCommon.targets</CustomBeforeMicrosoftCommonTargets>
83+
<CustomBeforeMicrosoftCommonCrossTargetingTargets>$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets</CustomBeforeMicrosoftCommonCrossTargetingTargets>
6384
</PropertyGroup>
6485

6586
<!-- Workaround: https://github.com/Microsoft/msbuild/issues/1293 -->

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.TargetFrameworkInference.targets

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ Copyright (c) .NET Foundation. All rights reserved.
7878

7979
<!--
8080
Append $(TargetFramework) directory to output and intermediate paths to prevent bin clashes between
81-
targets. However, we must leave OutputPath unset if it's not already as common targets use this to
82-
detect an invalid configuration or platform.
81+
targets.
8382
-->
8483
<PropertyGroup>
8584
<IntermediateOutputPath>$(IntermediateOutputPath)$(TargetFramework)\</IntermediateOutputPath>
86-
<OutputPath Condition="'$(OutputPath)' != ''">$(OutputPath)$(TargetFramework)\</OutputPath>
85+
<OutputPath>$(OutputPath)$(TargetFramework)\</OutputPath>
8786
</PropertyGroup>
8887

8988
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.IO;
5+
using System.Runtime.InteropServices;
6+
using Microsoft.NET.TestFramework;
7+
using Microsoft.NET.TestFramework.Assertions;
8+
using Microsoft.NET.TestFramework.Commands;
9+
using Xunit;
10+
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
11+
12+
namespace Microsoft.NET.Build.Tests
13+
{
14+
public class GivenThatWeWantToBuildASolutionWithNonAnyCPUPlatform
15+
{
16+
private TestAssetsManager _testAssetsManager = TestAssetsManager.TestProjectsAssetsManager;
17+
18+
[Fact]
19+
public void It_builds_solusuccessfully()
20+
{
21+
var testAsset = _testAssetsManager
22+
.CopyTestAsset("x64SolutionBuild")
23+
.WithSource()
24+
.Restore();
25+
26+
27+
var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot, "x64SolutionBuild.sln");
28+
buildCommand
29+
.Execute()
30+
.Should()
31+
.Pass();
32+
33+
buildCommand.GetOutputDirectory("netcoreapp1.0", Path.Combine("x64", "Debug"))
34+
.Should()
35+
.OnlyHaveFiles(new[] {
36+
"x64SolutionBuild.runtimeconfig.dev.json",
37+
"x64SolutionBuild.runtimeconfig.json",
38+
"x64SolutionBuild.deps.json",
39+
"x64SolutionBuild.dll",
40+
"x64SolutionBuild.pdb"
41+
});
42+
}
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.IO;
5+
using System.Runtime.InteropServices;
6+
using Microsoft.DotNet.Cli.Utils;
7+
using Microsoft.DotNet.InternalAbstractions;
8+
using Microsoft.NET.TestFramework;
9+
using Microsoft.NET.TestFramework.Assertions;
10+
using Microsoft.NET.TestFramework.Commands;
11+
using Xunit;
12+
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
13+
14+
namespace Microsoft.NET.Pack.Tests
15+
{
16+
public class GivenThatWeWantToPackASimpleLibrary
17+
{
18+
private TestAssetsManager _testAssetsManager = TestAssetsManager.TestProjectsAssetsManager;
19+
20+
[Fact]
21+
public void It_packs_successfully()
22+
{
23+
var testAsset = _testAssetsManager
24+
.CopyTestAsset("HelloWorld")
25+
.WithSource()
26+
.Restore();
27+
28+
new PackCommand(Stage0MSBuild, testAsset.TestRoot)
29+
.Execute()
30+
.Should()
31+
.Pass();
32+
33+
var outputDirectory = new DirectoryInfo(Path.Combine(testAsset.TestRoot, "bin", "Debug"));
34+
outputDirectory.Should().OnlyHaveFiles(new[] {
35+
"HelloWorld.1.0.0.nupkg",
36+
"netcoreapp1.0/HelloWorld.dll",
37+
"netcoreapp1.0/HelloWorld.pdb",
38+
"netcoreapp1.0/HelloWorld.deps.json",
39+
"netcoreapp1.0/HelloWorld.runtimeconfig.json",
40+
"netcoreapp1.0/HelloWorld.runtimeconfig.dev.json",
41+
});
42+
}
43+
}
44+
}

test/Microsoft.NET.Pack.Tests/Microsoft.NET.Pack.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
</PackageReference>
3737
</ItemGroup>
3838
<ItemGroup>
39+
<Compile Include="GivenThatWeWantToPackASimpleLibrary.cs" />
3940
<Compile Include="GivenThatWeWantToPackACrossTargetedLibrary.cs" />
4041
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
4142
</ItemGroup>

0 commit comments

Comments
 (0)