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" />
<ItemGroup>
<Sdk Include="Microsoft.Net.Sdk" Version="$(CLI_NETSDK_Version)" />
<Sdk Include="Microsoft.NET.Sdk" Version="$(CLI_NETSDK_Version)" />
</ItemGroup>
</Project>

View file

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

View file

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

View file

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

View file

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

View file

@ -4,7 +4,7 @@
<ItemGroup>
<!-- 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="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.Publish" Version="$(CLI_WEBSDK_Version)" />
<BundledSdk Include="Microsoft.NET.Sdk.Web.ProjectSystem" Version="$(CLI_WEBSDK_Version)" />

View file

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

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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_WEBSDK_Version>1.0.0-alpha-20161104-2-112</CLI_WEBSDK_Version>
</PropertyGroup>

View file

@ -12,5 +12,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public const string MstestTestAdapterVersion = "1.1.3-preview";
public const string MstestTestFrameworkVersion = "1.0.4-preview";
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 ProjectDirectory { get; }
public string OutputDirectory { get; }
public string SdkPackageVersion { get; }
public ProjectRootElement MSBuildProjectTemplate { get; }
public string SdkDefaultsFilePath { get; }
public MigrationSettings(
string projectDirectory,
string outputDirectory,
string sdkPackageVersion,
ProjectRootElement msBuildProjectTemplate,
string projectXprojFilePath=null,
string sdkDefaultsFilePath=null) : this(
projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath)
projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath)
{
MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null;
}
@ -32,11 +30,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public MigrationSettings(
string projectDirectory,
string outputDirectory,
string sdkPackageVersion,
string msBuildProjectTemplatePath,
string projectXprojFilePath=null,
string sdkDefaultsFilePath=null) : this(
projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath)
projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath)
{
_msBuildProjectTemplatePath = msBuildProjectTemplatePath;
MSBuildProjectTemplate = ProjectRootElement.Open(
@ -48,13 +45,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration
private MigrationSettings(
string projectDirectory,
string outputDirectory,
string sdkPackageVersion,
string projectXprojFilePath=null,
string sdkDefaultsFilePath=null)
{
ProjectDirectory = projectDirectory;
OutputDirectory = outputDirectory;
SdkPackageVersion = sdkPackageVersion;
ProjectXProjFilePath = projectXprojFilePath;
SdkDefaultsFilePath = sdkDefaultsFilePath;
}

View file

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

View file

@ -39,16 +39,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
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(
migrationRuleInputs,
migrationSettings,
@ -90,18 +80,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var type = project.GetProjectType();
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:
_transformApplicator.Execute(
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

@ -59,10 +59,6 @@ namespace Microsoft.DotNet.Tools.Migrate
var projectsToMigrate = GetProjectsToMigrate(_projectArg);
var msBuildTemplatePath = _templateFile ?? temporaryDotnetNewProject.MSBuildProjectPath;
var sdkVersion = _sdkVersion ?? temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
EnsureNotNull(sdkVersion, "Null Sdk Version");
MigrationReport migrationReport = null;
@ -73,7 +69,6 @@ namespace Microsoft.DotNet.Tools.Migrate
var migrationSettings = new MigrationSettings(
projectDirectory,
outputDirectory,
sdkVersion,
msBuildTemplatePath,
_xprojFilePath);
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 ExtensionsDirectoryName = "Extensions";
private const string SdksDirectoryName = "Sdks";
private readonly ForwardingApp _forwardingApp;
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
return Path.Combine(
AppContext.BaseDirectory,
ExtensionsDirectoryName);
SdksDirectoryName);
}
private static string GetRunCscPath()

View file

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

View file

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

View file

@ -1,5 +1,4 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -12,23 +11,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<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>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20161123-03" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.5-preview" />
<PackageReference Include="MSTest.TestFramework" Version="1.0.6-preview" />
</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">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -12,23 +11,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<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>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20161123-03" />
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta4-build1194" />
</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 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());
projectMigrator.Migrate(testSettings);
@ -46,7 +46,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
.Path;
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 report = projectMigrator.Migrate(testSettings);
@ -67,7 +67,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
.Path;
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 report = projectMigrator.Migrate(testSettings);

View file

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

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext =
ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
_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(
new[] {projectContext},
_mockProject,

View file

@ -40,7 +40,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").Path;
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(),
templateProj.AddPropertyGroup());
new MigrateBuildOptionsRule().Apply(testSettings, testInputs);

View file

@ -49,31 +49,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
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]
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"));
}
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)
{
@ -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)
{
@ -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;
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 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(),
mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -51,7 +51,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
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(),
mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -71,7 +71,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
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(),
mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -97,7 +97,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
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());
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 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(),
mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
@ -338,7 +338,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(appDirectory, targetFramework);
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(),
mockProj.AddPropertyGroup());
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 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);
new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);
@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
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);
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 mockProj = ProjectRootElement.Create();
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
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(
projectContexts,
mockProj,
@ -79,7 +79,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
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(
projectContexts,
mockProj,
@ -109,7 +109,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var mockProj = ProjectRootElement.Create();
// Run BuildOptionsRule
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, mockProj);
var migrationInputs = new MigrationRuleInputs(
projectContexts,
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)
{
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,
project.AddItemGroup(),
project.AddPropertyGroup(),

View file

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