use Sdks attribute in dotnet new templates (#4916)

* Move dotnet-new templates to Sdk attribute

* Update to MSBuild 15.1.0-preview-000454-01

To pick up a fix for Microsoft/msbuild#1431.

* Fix template newlines

* Fix casing on Microsoft.Net.Sdk

* Move migration test csproj's to Sdk attribute

* Disable parallel sdk restore

Each SDK restore operation will try to manipulate the same assets.json file since the dependency name&version are injected into a common csproj file. This can cause runtime failures when two NuGets try to restore the project at once.

* Make casing of SDK 'NET' and not 'Net'

* Remove redundatn imports

* Fix test string

* Additional race

* Replacing the SDK with the Web.Sdk when it is a Web project.

* Fixing the test by writting the csproj before running the migration rule.
This commit is contained in:
Piotr Puszkiewicz 2016-12-04 22:31:58 -08:00 committed by GitHub
parent dc3d88c587
commit d6cab4af58
30 changed files with 179 additions and 177 deletions

View file

@ -2,6 +2,6 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup> <ItemGroup>
<Sdk Include="Microsoft.Net.Sdk" Version="$(CLI_NETSDK_Version)" /> <Sdk Include="Microsoft.NET.Sdk" Version="$(CLI_NETSDK_Version)" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup> <PropertyGroup>
@ -14,14 +13,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>$(CLI_NETSDK_Version)</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="NETStandard.Library"> <PackageReference Include="NETStandard.Library">
<Version>1.6.0</Version> <Version>1.6.0</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup> <PropertyGroup>
@ -14,14 +13,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>$(CLI_NETSDK_Version)</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="NETStandard.Library"> <PackageReference Include="NETStandard.Library">
<Version>1.6.0</Version> <Version>1.6.0</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup> <PropertyGroup>
@ -14,14 +13,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>$(CLI_NETSDK_Version)</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="NETStandard.Library"> <PackageReference Include="NETStandard.Library">
<Version>1.6.0</Version> <Version>1.6.0</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -16,6 +16,9 @@
Outputs="@(SdkContent->'$(SdkLayoutDirectory)/%(RecursiveDir)%(FileName)%(Extension)')"> Outputs="@(SdkContent->'$(SdkLayoutDirectory)/%(RecursiveDir)%(FileName)%(Extension)')">
<Copy SourceFiles="@(SdkContent)" <Copy SourceFiles="@(SdkContent)"
DestinationFiles="@(SdkContent->'$(SdkLayoutDirectory)/%(RecursiveDir)%(FileName)%(Extension)')" /> DestinationFiles="@(SdkContent->'$(SdkLayoutDirectory)/%(RecursiveDir)%(FileName)%(Extension)')" />
<Message Text="Copied Sdk $(SdkPackageName) from $(SdkNuPkgPath) to $(SdkLayoutDirectory)."
Importance="High" />
</Target> </Target>
<Target Name="GetSdkItemsToCopy"> <Target Name="GetSdkItemsToCopy">

View file

@ -4,7 +4,7 @@
<ItemGroup> <ItemGroup>
<!-- CLI cannot use the latest SDK until we move away from SDK PackageRef --> <!-- CLI cannot use the latest SDK until we move away from SDK PackageRef -->
<BundledSdk Include="NuGet.Build.Tasks.Pack" Version="4.0.0-rc2" /> <BundledSdk Include="NuGet.Build.Tasks.Pack" Version="4.0.0-rc2" />
<BundledSdk Include="Microsoft.Net.Sdk" Version="1.0.0-alpha-20161203-1" /> <BundledSdk Include="Microsoft.NET.Sdk" Version="1.0.0-alpha-20161203-1" />
<BundledSdk Include="Microsoft.NET.Sdk.Web" Version="$(CLI_WEBSDK_Version)" /> <BundledSdk Include="Microsoft.NET.Sdk.Web" Version="$(CLI_WEBSDK_Version)" />
<BundledSdk Include="Microsoft.NET.Sdk.Publish" Version="$(CLI_WEBSDK_Version)" /> <BundledSdk Include="Microsoft.NET.Sdk.Publish" Version="$(CLI_WEBSDK_Version)" />
<BundledSdk Include="Microsoft.NET.Sdk.Web.ProjectSystem" Version="$(CLI_WEBSDK_Version)" /> <BundledSdk Include="Microsoft.NET.Sdk.Web.ProjectSystem" Version="$(CLI_WEBSDK_Version)" />

View file

@ -251,7 +251,7 @@
<Properties> <Properties>
CLIBuildDll=$(CLIBuildDll); CLIBuildDll=$(CLIBuildDll);
NuGetPackagesDir=$(NuGetPackagesDir); NuGetPackagesDir=$(NuGetPackagesDir);
SdkLayoutDirectory=$(SdkOutputDirectory)/Extensions/%(BundledSdk.Identity); SdkLayoutDirectory=$(SdkOutputDirectory)/Sdks/%(BundledSdk.Identity);
SdkPackageName=%(BundledSdk.Identity); SdkPackageName=%(BundledSdk.Identity);
SdkPackageVersion=%(BundledSdk.Version); SdkPackageVersion=%(BundledSdk.Version);
Stage0Directory=$(Stage0Directory) Stage0Directory=$(Stage0Directory)
@ -260,7 +260,7 @@
</ItemGroup> </ItemGroup>
<MSBuild <MSBuild
BuildInParallel="True" BuildInParallel="False"
Projects="@(SdksToBundle)"> Projects="@(SdksToBundle)">
</MSBuild> </MSBuild>
</Target> </Target>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<CLI_MSBuild_Version>15.1.0-preview-000451-02</CLI_MSBuild_Version> <CLI_MSBuild_Version>15.1.0-preview-000454-01</CLI_MSBuild_Version>
<CLI_NETSDK_Version>1.0.0-alpha-20161104-2</CLI_NETSDK_Version> <CLI_NETSDK_Version>1.0.0-alpha-20161104-2</CLI_NETSDK_Version>
<CLI_WEBSDK_Version>1.0.0-alpha-20161104-2-112</CLI_WEBSDK_Version> <CLI_WEBSDK_Version>1.0.0-alpha-20161104-2-112</CLI_WEBSDK_Version>
</PropertyGroup> </PropertyGroup>

View file

@ -12,5 +12,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string MstestTestAdapterVersion = "1.1.3-preview"; public const string MstestTestAdapterVersion = "1.1.3-preview";
public const string MstestTestFrameworkVersion = "1.0.4-preview"; public const string MstestTestFrameworkVersion = "1.0.4-preview";
public const string BundleMinifierToolVersion = "2.2.301"; public const string BundleMinifierToolVersion = "2.2.301";
public const string WebSdkPackageVersion = "1.0.0-alpha-20161117-1-119" ;
} }
} }

View file

@ -13,18 +13,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public string ProjectXProjFilePath { get; } public string ProjectXProjFilePath { get; }
public string ProjectDirectory { get; } public string ProjectDirectory { get; }
public string OutputDirectory { get; } public string OutputDirectory { get; }
public string SdkPackageVersion { get; }
public ProjectRootElement MSBuildProjectTemplate { get; } public ProjectRootElement MSBuildProjectTemplate { get; }
public string SdkDefaultsFilePath { get; } public string SdkDefaultsFilePath { get; }
public MigrationSettings( public MigrationSettings(
string projectDirectory, string projectDirectory,
string outputDirectory, string outputDirectory,
string sdkPackageVersion,
ProjectRootElement msBuildProjectTemplate, ProjectRootElement msBuildProjectTemplate,
string projectXprojFilePath=null, string projectXprojFilePath=null,
string sdkDefaultsFilePath=null) : this( string sdkDefaultsFilePath=null) : this(
projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath) projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath)
{ {
MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null; MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null;
} }
@ -32,11 +30,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public MigrationSettings( public MigrationSettings(
string projectDirectory, string projectDirectory,
string outputDirectory, string outputDirectory,
string sdkPackageVersion,
string msBuildProjectTemplatePath, string msBuildProjectTemplatePath,
string projectXprojFilePath=null, string projectXprojFilePath=null,
string sdkDefaultsFilePath=null) : this( string sdkDefaultsFilePath=null) : this(
projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath) projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath)
{ {
_msBuildProjectTemplatePath = msBuildProjectTemplatePath; _msBuildProjectTemplatePath = msBuildProjectTemplatePath;
MSBuildProjectTemplate = ProjectRootElement.Open( MSBuildProjectTemplate = ProjectRootElement.Open(
@ -48,13 +45,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration
private MigrationSettings( private MigrationSettings(
string projectDirectory, string projectDirectory,
string outputDirectory, string outputDirectory,
string sdkPackageVersion,
string projectXprojFilePath=null, string projectXprojFilePath=null,
string sdkDefaultsFilePath=null) string sdkDefaultsFilePath=null)
{ {
ProjectDirectory = projectDirectory; ProjectDirectory = projectDirectory;
OutputDirectory = outputDirectory; OutputDirectory = outputDirectory;
SdkPackageVersion = sdkPackageVersion;
ProjectXProjFilePath = projectXprojFilePath; ProjectXProjFilePath = projectXprojFilePath;
SdkDefaultsFilePath = sdkDefaultsFilePath; SdkDefaultsFilePath = sdkDefaultsFilePath;
} }

View file

@ -74,7 +74,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration
var projectDir = Path.GetDirectoryName(project.ProjectFilePath); var projectDir = Path.GetDirectoryName(project.ProjectFilePath);
var settings = new MigrationSettings(projectDir, var settings = new MigrationSettings(projectDir,
projectDir, projectDir,
rootSettings.SdkPackageVersion,
tempMSBuildProjectTemplate); tempMSBuildProjectTemplate);
MigrateProject(settings); MigrateProject(settings);
projectMigrationReports.Add(MigrateProject(settings)); projectMigrationReports.Add(MigrateProject(settings));

View file

@ -39,16 +39,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var noFrameworkPackageReferenceItemGroup = migrationRuleInputs.OutputMSBuildProject.AddItemGroup(); var noFrameworkPackageReferenceItemGroup = migrationRuleInputs.OutputMSBuildProject.AddItemGroup();
// Inject Sdk dependency
_transformApplicator.Execute(
SdkPackageDependencyTransform.Transform(
new PackageDependencyInfo
{
Name = PackageConstants.SdkPackageName,
Version = migrationSettings.SdkPackageVersion,
PrivateAssets = "All"
}), noFrameworkPackageReferenceItemGroup, mergeExisting: false);
AddProjectTypeSpecificDependencies( AddProjectTypeSpecificDependencies(
migrationRuleInputs, migrationRuleInputs,
migrationSettings, migrationSettings,
@ -90,18 +80,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var type = project.GetProjectType(); var type = project.GetProjectType();
switch (type) switch (type)
{ {
case ProjectType.Web:
_transformApplicator.Execute(
SdkPackageDependencyTransform.Transform(
new PackageDependencyInfo
{
Name = PackageConstants.WebSdkPackageName,
Version = migrationSettings.SdkPackageVersion,
PrivateAssets = "All"
}),
noFrameworkPackageReferenceItemGroup,
mergeExisting: false);
break;
case ProjectType.Test: case ProjectType.Test:
_transformApplicator.Execute( _transformApplicator.Execute(
PackageDependencyInfoTransform().Transform( PackageDependencyInfoTransform().Transform(

View file

@ -0,0 +1,40 @@
// 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 Microsoft.Build.Construction;
namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{
//HACK to workaround https://github.com/Microsoft/msbuild/issues/1429
internal class MigrateWebSdkRule : IMigrationRule
{
private static string GetContainingFolderName(string projectDirectory)
{
projectDirectory = projectDirectory.TrimEnd(new char[] { '/', '\\' });
return Path.GetFileName(projectDirectory);
}
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
{
var project = migrationRuleInputs.DefaultProjectContext.ProjectFile;
var type = project.GetProjectType();
if(type == ProjectType.Web)
{
ReplaceSdkWithWebSdk(migrationSettings);
}
}
private void ReplaceSdkWithWebSdk(MigrationSettings migrationSettings)
{
string csprojName = $"{GetContainingFolderName(migrationSettings.ProjectDirectory)}.csproj";
var outputProject = Path.Combine(migrationSettings.OutputDirectory, csprojName);
var csprojContent = File.ReadAllText(outputProject);
csprojContent = csprojContent.Replace("Sdk=\"Microsoft.NET.Sdk\"", "Sdk=\"Microsoft.NET.Sdk.Web\"");
File.WriteAllText(outputProject, csprojContent);
}
}
}

View file

@ -60,10 +60,6 @@ namespace Microsoft.DotNet.Tools.Migrate
var msBuildTemplatePath = _templateFile ?? temporaryDotnetNewProject.MSBuildProjectPath; var msBuildTemplatePath = _templateFile ?? temporaryDotnetNewProject.MSBuildProjectPath;
var sdkVersion = _sdkVersion ?? temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
EnsureNotNull(sdkVersion, "Null Sdk Version");
MigrationReport migrationReport = null; MigrationReport migrationReport = null;
foreach (var project in projectsToMigrate) foreach (var project in projectsToMigrate)
@ -73,7 +69,6 @@ namespace Microsoft.DotNet.Tools.Migrate
var migrationSettings = new MigrationSettings( var migrationSettings = new MigrationSettings(
projectDirectory, projectDirectory,
outputDirectory, outputDirectory,
sdkVersion,
msBuildTemplatePath, msBuildTemplatePath,
_xprojFilePath); _xprojFilePath);
var projectMigrationReport = new ProjectMigrator().Migrate(migrationSettings, _skipProjectReferences); var projectMigrationReport = new ProjectMigrator().Migrate(migrationSettings, _skipProjectReferences);

View file

@ -18,7 +18,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
private const string MSBuildExeName = "MSBuild.dll"; private const string MSBuildExeName = "MSBuild.dll";
private const string ExtensionsDirectoryName = "Extensions"; private const string SdksDirectoryName = "Sdks";
private readonly ForwardingApp _forwardingApp; private readonly ForwardingApp _forwardingApp;
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
return Path.Combine( return Path.Combine(
AppContext.BaseDirectory, AppContext.BaseDirectory,
ExtensionsDirectoryName); SdksDirectoryName);
} }
private static string GetRunCscPath() private static string GetRunCscPath()

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@ -12,14 +11,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore.App"> <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework> <TargetFramework>netstandard1.4</TargetFramework>
@ -11,14 +10,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NETStandard.Library"> <PackageReference Include="NETStandard.Library" Version="1.6" />
<Version>1.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@ -12,23 +11,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore.App"> <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<Version>1.0.1</Version> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20161123-03" />
</PackageReference> <PackageReference Include="MSTest.TestAdapter" Version="1.1.5-preview" />
<PackageReference Include="Microsoft.NET.Sdk"> <PackageReference Include="MSTest.TestFramework" Version="1.0.6-preview" />
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0-preview-20161123-03</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>1.1.5-preview</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>1.0.6-preview</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@ -12,23 +11,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore.App"> <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<Version>1.0.1</Version> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20161123-03" />
</PackageReference> <PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="Microsoft.NET.Sdk"> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta4-build1194" />
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0-preview-20161123-03</Version>
</PackageReference>
<PackageReference Include="xunit">
<Version>2.2.0-beta4-build3444</Version>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<Version>2.2.0-beta4-build1194</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View file

@ -27,7 +27,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory); var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testProjectDirectory, outputDirectory, "1.0.0", mockProj); var testSettings = new MigrationSettings(testProjectDirectory, outputDirectory, mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
projectMigrator.Migrate(testSettings); projectMigrator.Migrate(testSettings);
@ -46,7 +46,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
.Path; .Path;
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", mockProj); var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
var report = projectMigrator.Migrate(testSettings); var report = projectMigrator.Migrate(testSettings);
@ -67,7 +67,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
.Path; .Path;
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", mockProj); var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
var report = projectMigrator.Migrate(testSettings); var report = projectMigrator.Migrate(testSettings);

View file

@ -17,7 +17,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
private JObject _projectJson; private JObject _projectJson;
private bool _baseDefined = false; private bool _baseDefined = false;
private bool _baseProjectDirectory;
public ProjectJsonBuilder(TestAssetsManager testAssetsManager) public ProjectJsonBuilder(TestAssetsManager testAssetsManager)
{ {

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = var projectContext =
ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
_mockProject = ProjectRootElement.Create(); _mockProject = ProjectRootElement.Create();
var testSettings = new MigrationSettings(projectDirectory, projectDirectory, "1.0.0", _mockProject, null); var testSettings = new MigrationSettings(projectDirectory, projectDirectory, _mockProject, null);
var testInputs = new MigrationRuleInputs( var testInputs = new MigrationRuleInputs(
new[] {projectContext}, new[] {projectContext},
_mockProject, _mockProject,

View file

@ -40,7 +40,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").Path; var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").Path;
var projectContext = ProjectContext.Create(testProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(testProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", templateProj); var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, templateProj);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, templateProj, templateProj.AddItemGroup(), var testInputs = new MigrationRuleInputs(new[] {projectContext}, templateProj, templateProj.AddItemGroup(),
templateProj.AddPropertyGroup()); templateProj.AddPropertyGroup());
new MigrateBuildOptionsRule().Apply(testSettings, testInputs); new MigrateBuildOptionsRule().Apply(testSettings, testInputs);

View file

@ -49,31 +49,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
privateAssetsMetadata.Value.Should().Be("All"); privateAssetsMetadata.Value.Should().Be("All");
} }
[Fact]
public void It_migrates_web_projects_to_have_web_sdk_PrivateAssets()
{
var mockProj = RunPackageDependenciesRuleOnPj(@"
{
""buildOptions"": {
""emitEntryPoint"": true
},
""dependencies"": {
""Microsoft.AspNetCore.Mvc"" : {
""version"": ""1.0.0""
}
},
""frameworks"": {
""netcoreapp1.0"": {}
}
}");
var packageRef = mockProj.Items.FirstOrDefault(i =>
i.Include == "Microsoft.NET.Sdk.Web" && i.ItemType == "PackageReference");
packageRef.Should().NotBeNull();
packageRef.GetMetadataWithName("PrivateAssets").Value.Should().NotBeNull().And.Be("All");
}
[Fact] [Fact]
public void It_migrates_suppress_parent_array_to_PrivateAssets() public void It_migrates_suppress_parent_array_to_PrivateAssets()
{ {
@ -431,7 +406,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference")); i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference"));
} }
private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple<string, string, string>[] packageSpecs) new private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple<string, string, string>[] packageSpecs)
{ {
foreach (var packageSpec in packageSpecs) foreach (var packageSpec in packageSpecs)
{ {
@ -449,7 +424,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
} }
private void EmitsToolReferences(ProjectRootElement mockProj, params Tuple<string, string>[] toolSpecs) new private void EmitsToolReferences(ProjectRootElement mockProj, params Tuple<string, string>[] toolSpecs)
{ {
foreach (var toolSpec in toolSpecs) foreach (var toolSpec in toolSpecs)
{ {
@ -465,7 +440,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
} }
private ProjectRootElement RunPackageDependenciesRuleOnPj(string s, string testDirectory = null) new private ProjectRootElement RunPackageDependenciesRuleOnPj(string s, string testDirectory = null)
{ {
testDirectory = testDirectory ?? Temp.CreateDirectory().Path; testDirectory = testDirectory ?? Temp.CreateDirectory().Path;
return TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[] return TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[]

View file

@ -27,7 +27,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
mockProj.AddPropertyGroup()); mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -51,7 +51,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
mockProj.AddPropertyGroup()); mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -71,7 +71,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
mockProj.AddPropertyGroup()); mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -97,7 +97,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj); var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup()); var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup());
Action action = () => new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); Action action = () => new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -260,7 +260,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.Net451); var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.Net451);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
mockProj.AddPropertyGroup()); mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -338,7 +338,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, targetFramework); var projectContext = ProjectContext.Create(appDirectory, targetFramework);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null); var testSettings = new MigrationSettings(appDirectory, appDirectory, mockProj, null);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(), var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
mockProj.AddPropertyGroup()); mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs); new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

View file

@ -34,7 +34,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var testSettings = new MigrationSettings(projectDir, projectDir, "1.0.0", default(ProjectRootElement)); var testSettings = new MigrationSettings(projectDir, projectDir, default(ProjectRootElement));
var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null); var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null);
new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs); new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);
@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var testSettings = new MigrationSettings(projectDir, projectDir, "1.0.0", default(ProjectRootElement)); var testSettings = new MigrationSettings(projectDir, projectDir, default(ProjectRootElement));
var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null); var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null);
new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs); new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);

View file

@ -30,7 +30,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs( var migrationInputs = new MigrationRuleInputs(
new[] { projectContext }, new[] { projectContext },
mockProj, mockProj,
@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs( var migrationInputs = new MigrationRuleInputs(
projectContexts, projectContexts,
mockProj, mockProj,
@ -79,7 +79,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory); var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs( var migrationInputs = new MigrationRuleInputs(
projectContexts, projectContexts,
mockProj, mockProj,
@ -109,7 +109,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
// Run BuildOptionsRule // Run BuildOptionsRule
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj); var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs( var migrationInputs = new MigrationRuleInputs(
projectContexts, projectContexts,
mockProj, mockProj,

View file

@ -0,0 +1,64 @@
// 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 Microsoft.Build.Construction;
using Microsoft.DotNet.Tools.Test.Utilities;
using System.Linq;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
using System;
using System.IO;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
public class GivenThatIWantToMigrateWebProjects : PackageDependenciesTestBase
{
[Fact]
public void ItMigratesWebProjectsToHaveWebSdkInTheSdkAttribute()
{
var csprojFilePath = RunMigrateWebSdkRuleOnPj(@"
{
""buildOptions"": {
""emitEntryPoint"": true
},
""dependencies"": {
""Microsoft.AspNetCore.Mvc"" : {
""version"": ""1.0.0""
}
},
""frameworks"": {
""netcoreapp1.0"": {}
}
}");
File.ReadAllText(csprojFilePath).Should().Contain(@"Sdk=""Microsoft.NET.Sdk.Web""");
}
private string RunMigrateWebSdkRuleOnPj(string s, string testDirectory = null)
{
testDirectory = testDirectory ?? Temp.CreateDirectory().Path;
var csprojFilePath = Path.Combine(testDirectory, $"{GetContainingFolderName(testDirectory)}.csproj");
File.WriteAllText(csprojFilePath, @"
<Project Sdk=""Microsoft.NET.Sdk"" ToolsVersion=""15.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup />
<ItemGroup />
</Project>");
TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[]
{
new MigrateWebSdkRule()
}, s, testDirectory);
return csprojFilePath;
}
private static string GetContainingFolderName(string projectDirectory)
{
projectDirectory = projectDirectory.TrimEnd(new char[] { '/', '\\' });
return Path.GetFileName(projectDirectory);
}
}
}

View file

@ -28,7 +28,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
ProjectContext projectContext, string testDirectory, ProjectRootElement xproj) ProjectContext projectContext, string testDirectory, ProjectRootElement xproj)
{ {
var project = ProjectRootElement.Create(); var project = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", project); var testSettings = new MigrationSettings(testDirectory, testDirectory, project);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, project, var testInputs = new MigrationRuleInputs(new[] {projectContext}, project,
project.AddItemGroup(), project.AddItemGroup(),
project.AddPropertyGroup(), project.AddPropertyGroup(),

View file

@ -180,7 +180,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
if (tasksToAwait.Any()) if (tasksToAwait.Any())
{ {
Task.WaitAll(tasksToAwait.ToArray()); try
{
Task.WaitAll(tasksToAwait.ToArray());
}
catch (System.ObjectDisposedException e)
{
taskErr = null;
taskOut = null;
}
} }
var result = new CommandResult( var result = new CommandResult(
@ -244,7 +253,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
if (tasksToAwait.Any()) if (tasksToAwait.Any())
{ {
Task.WaitAll(tasksToAwait.ToArray()); try
{
Task.WaitAll(tasksToAwait.ToArray());
}
catch (System.ObjectDisposedException e)
{
taskErr = null;
taskOut = null;
}
} }
var result = new CommandResult( var result = new CommandResult(