Skip to content
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
12 changes: 12 additions & 0 deletions TestAssets/TestProjects/x64SolutionBuild/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
31 changes: 31 additions & 0 deletions TestAssets/TestProjects/x64SolutionBuild/x64SolutionBuild.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" />

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

<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>0.0.0</Version>
</PackageReference>
</ItemGroup>

<Target Name="CheckPlatform" BeforeTargets="Build">
<Error Condition="'$(Platform)' != 'x64'" Text="This test project expects to be built via solution and have Platform=x64" />
</Target>

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
21 changes: 21 additions & 0 deletions TestAssets/TestProjects/x64SolutionBuild/x64SolutionBuild.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.25827.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "x64SolutionBuild", "x64SolutionBuild.csproj", "{544B615E-491F-4C80-9918-B10A6FB4B3CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Debug|x64.ActiveCfg = Debug|x64
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Debug|x64.Build.0 = Debug|x64
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Release|x64.ActiveCfg = Release|Any CPU
{544B615E-491F-4C80-9918-B10A6FB4B3CD}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<None Include="buildCrossTargeting\Microsoft.NET.Sdk.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="build\Microsoft.NET.DefaultOutputPaths.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="build\Microsoft.NET.RuntimeIdentifierInference.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -83,6 +86,9 @@
<None Include="build\Microsoft.NET.GenerateAssemblyInfo.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="build\Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="build\Microsoft.NET.Sdk.VisualBasic.props">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
***********************************************************************************************
Microsoft.NET.DefaultOutputPaths.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
Apply the same default output paths as Microsoft.Common.targets now since we're running before them,
but need to adjust them and/or make decisions in terms of them.
Also note that common targets only set a default OutputPath if neither configuration nor
platform were set by the user. This was used to validate that a valid configuration is passed,
assuming the convention maintained by VS that every Configuration|Platform combination had
an explicit OutputPath. Since we now want to support leaner project files with less
duplication and more automatic defaults, we always set a default OutputPath and can no
longer depend on that convention for validation. Getting validation re-enabled with a
different mechanism is tracked by https://github.com/dotnet/sdk/issues/350
-->
<PropertyGroup>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also have the Configuration and Platform defaults in Microsoft.NET.Sdk.props, is there a reason to also put it in this targets file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just being defensive in case the props aren't imported, though you probably have other problems. Regardless, the duplication pre-exists this change, so I'll leave de-duping as a separate exercise.

<PlatformName Condition="'$(PlatformName)' == ''">$(Platform)</PlatformName>

<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">bin\</BaseOutputPath>
<BaseOutputPath Condition="!HasTrailingSlash('$(BaseOutputPath)')">$(BaseOutputPath)\</BaseOutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseOutputPath)$(Configuration)\</OutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseOutputPath)$(PlatformName)\$(Configuration)\</OutputPath>
<OutputPath Condition="!HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>

<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' == 'AnyCPU' ">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' != 'AnyCPU' ">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
<IntermediateOutputPath Condition="!HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)\</IntermediateOutputPath>
</PropertyGroup>

<!-- Set the package output path (for nuget pack target) now, before the TargetFramework is appended -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a way to solve this right now, but it seems to me that you wouldn't want the NuGet package generated in an x86 or x64 folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed #329 to make sure we have settled on default output paths. There is definitely tension between traditional VS concept of $(Platform) and nuget concept of $(RuntimeIdentifier), etc. Everything is configurable, though, so I think we're bound to have some compromise on the defaults.

<PropertyGroup>
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(OutputPath)</PackageOutputPath>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
Apply the same defaults as Microsoft.Common.targets now since we're running before them,
but need to adjust them and/or make decisions in terms of them.
-->
<PropertyGroup>
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
<PlatformName Condition="'$(PlatformName)' == ''">$(Platform)</PlatformName>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<OutputPath Condition="'$(OutputPath)' != '' and !HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' == 'AnyCPU' ">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' != 'AnyCPU' ">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>

<!-- Set default intermediate and output paths -->
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />

<!--
Expand TargetFramework (if set) to TargetFrameworkIdentifier and TargetFrameworkVersion,
and adjust intermediate and output paths to include it.
Expand All @@ -35,7 +23,7 @@ Copyright (c) .NET Foundation. All rights reserved.

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
***********************************************************************************************
Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Copyright (c) .NET Foundation. All rights reserved.
<WarningLevel>4</WarningLevel>
<NoWarn>1701;1702;1705</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<VBRuntime>Embed</VBRuntime>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineTrace>true</DefineTrace>
</PropertyGroup>

Expand Down
33 changes: 27 additions & 6 deletions src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ Copyright (c) .NET Foundation. All rights reserved.
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<!-- Default configuration and platform to Debug|AnyCPU-->
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>

<!--
Ensure VS sees two default configurations: Debug|AnyCPU and Release|AnyCPU

This is temproary until we have designed and implemented a new configuration management scheme,
which is tracked by https://github.com/dotnet/sdk/issues/350. In the meantime, one consequence of
defining these defaults here with the old inference-from-usage scheme here is that the user cannot
remove or rename them.
-->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "/>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "/>

<!-- User-facing configuration-agnostic defaults -->
<PropertyGroup>
<OutputType>Library</OutputType>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform>AnyCPU</Platform>
<FileAlignment>512</FileAlignment>
<ErrorReport>prompt</ErrorReport>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
Expand All @@ -28,14 +43,19 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<!-- User-facing configuration-specific defaults -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x64' ">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

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

<!-- Temp Hack: 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. -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hack -> workaround (or did you already change this in another PR?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is already fixed in another PR.

<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.BeforeCommon.targets</CustomBeforeMicrosoftCommonTargets>
<CustomBeforeMicrosoftCommonCrossTargetingTargets>$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets</CustomBeforeMicrosoftCommonCrossTargetingTargets>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.CSharp.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ Copyright (c) .NET Foundation. All rights reserved.

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.IO;
using System.Runtime.InteropServices;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Xunit;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;

namespace Microsoft.NET.Build.Tests
{
public class GivenThatWeWantToBuildASolutionWithNonAnyCPUPlatform
{
private TestAssetsManager _testAssetsManager = TestAssetsManager.TestProjectsAssetsManager;

[Fact]
public void It_builds_solusuccessfully()
{
var testAsset = _testAssetsManager
.CopyTestAsset("x64SolutionBuild")
.WithSource()
.Restore();


var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot, "x64SolutionBuild.sln");
buildCommand
.Execute()
.Should()
.Pass();

buildCommand.GetOutputDirectory("netcoreapp1.0", Path.Combine("x64", "Debug"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably rename this parameter or otherwise refactor so that we're not passing in x64\Debug as the configuration parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll follow up with a separate test-only change to clean this up.

.Should()
.OnlyHaveFiles(new[] {
"x64SolutionBuild.runtimeconfig.dev.json",
"x64SolutionBuild.runtimeconfig.json",
"x64SolutionBuild.deps.json",
"x64SolutionBuild.dll",
"x64SolutionBuild.pdb"
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.IO;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Xunit;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;

namespace Microsoft.NET.Pack.Tests
{
public class GivenThatWeWantToPackASimpleLibrary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test related to the OutputPath changes or is it just filling in more general test coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is related to the package output path being correct. There are different import paths for x-targeted and single-targeted cases and we only tested x-targeted. My first attempt at fixing this broke the x-targeted test and then I found it prudent to test both cases to prevent fixing one while breaking the other.

{
private TestAssetsManager _testAssetsManager = TestAssetsManager.TestProjectsAssetsManager;

[Fact]
public void It_packs_successfully()
{
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.WithSource()
.Restore();

new PackCommand(Stage0MSBuild, testAsset.TestRoot)
.Execute()
.Should()
.Pass();

var outputDirectory = new DirectoryInfo(Path.Combine(testAsset.TestRoot, "bin", "Debug"));
outputDirectory.Should().OnlyHaveFiles(new[] {
"HelloWorld.1.0.0.nupkg",
"netcoreapp1.0/HelloWorld.dll",
"netcoreapp1.0/HelloWorld.pdb",
"netcoreapp1.0/HelloWorld.deps.json",
"netcoreapp1.0/HelloWorld.runtimeconfig.json",
"netcoreapp1.0/HelloWorld.runtimeconfig.dev.json",
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="GivenThatWeWantToPackASimpleLibrary.cs" />
<Compile Include="GivenThatWeWantToPackACrossTargetedLibrary.cs" />
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
</ItemGroup>
Expand Down
Loading