This commit is contained in:
Родитель
8f5f3e201e
Коммит
68baf8a34c
|
@ -5,5 +5,8 @@
|
|||
<add key="nugetbuild" value="https://www.myget.org/F/nugetbuild/api/v3/index.json" />
|
||||
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
|
||||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
||||
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
|
||||
<add key="dotnet-cli" value="https://dotnet.myget.org/F/dotnet-cli/api/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
|
|
|
@ -72,6 +72,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Projec
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.ProjectModel.MsBuild.Sources", "src\Microsoft.Extensions.ProjectModel.MsBuild.Sources\Microsoft.Extensions.ProjectModel.MsBuild.Sources.xproj", "{7362AE32-7753-4E7C-86D0-DCA86AF413FA}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.VisualStudio.Web.CodeGeneration.MSBuild", "src\Microsoft.VisualStudio.Web.CodeGeneration.Msbuild\Microsoft.VisualStudio.Web.CodeGeneration.MSBuild.xproj", "{84D9AF9F-1AA5-4041-A983-33F28A075395}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -178,6 +180,10 @@ Global
|
|||
{7362AE32-7753-4E7C-86D0-DCA86AF413FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7362AE32-7753-4E7C-86D0-DCA86AF413FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7362AE32-7753-4E7C-86D0-DCA86AF413FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{84D9AF9F-1AA5-4041-A983-33F28A075395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{84D9AF9F-1AA5-4041-A983-33F28A075395}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{84D9AF9F-1AA5-4041-A983-33F28A075395}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{84D9AF9F-1AA5-4041-A983-33F28A075395}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -209,5 +215,6 @@ Global
|
|||
{8A97D718-0681-43C5-A70B-535DBBDF4FA1} = {B6CF7723-2947-411F-9AF1-35C09FAE514E}
|
||||
{1F643A36-A1FC-4502-9D03-75837F20E1A4} = {B6CF7723-2947-411F-9AF1-35C09FAE514E}
|
||||
{7362AE32-7753-4E7C-86D0-DCA86AF413FA} = {B6CF7723-2947-411F-9AF1-35C09FAE514E}
|
||||
{84D9AF9F-1AA5-4041-A983-33F28A075395} = {B6CF7723-2947-411F-9AF1-35C09FAE514E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>84d9af9f-1aa5-4041-a983-33f28a075395</ProjectGuid>
|
||||
<RootNamespace>Microsoft.VisualStudio.Web.CodeGeneration.Msbuild</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,124 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.ProjectModel;
|
||||
using Microsoft.Extensions.ProjectModel.Resolution;
|
||||
using NuGet.Frameworks;
|
||||
using Microsoft.VisualStudio.Web.CodeGeneration.Utils;
|
||||
|
||||
namespace Microsoft.VisualStudio.Web.CodeGeneration.Msbuild
|
||||
{
|
||||
public class MsBuildProjectContext : IProjectContext
|
||||
{
|
||||
|
||||
public MsBuildProjectContext(
|
||||
string assemblyFullPath,
|
||||
string assemblyName,
|
||||
IEnumerable<ResolvedReference> compilationAssemblies,
|
||||
IEnumerable<string> compilationItems,
|
||||
string config,
|
||||
string configuration,
|
||||
string depsJson,
|
||||
IEnumerable<string> embededItems,
|
||||
bool isClassLibrary,
|
||||
IEnumerable<DependencyDescription> packageDependencies,
|
||||
string packageLockFile,
|
||||
string packagesDirectory,
|
||||
string platform,
|
||||
string projectFullPath,
|
||||
string projectName,
|
||||
IEnumerable<string> projectReferences,
|
||||
string rootNamespace,
|
||||
string runtimeConfigJson,
|
||||
string targetDirectory,
|
||||
NuGetFramework targetFramework)
|
||||
{
|
||||
Requires.NotNullOrEmpty(assemblyFullPath, nameof(assemblyFullPath));
|
||||
Requires.NotNullOrEmpty(assemblyName, nameof(assemblyName));
|
||||
Requires.NotNull(compilationAssemblies, nameof(compilationAssemblies));
|
||||
Requires.NotNull(compilationItems, nameof(compilationItems));
|
||||
Requires.NotNullOrEmpty(config, nameof(config));
|
||||
Requires.NotNullOrEmpty(configuration, nameof(configuration));
|
||||
Requires.NotNullOrEmpty(depsJson, nameof(depsJson));
|
||||
Requires.NotNull(embededItems, nameof(embededItems));
|
||||
Requires.NotNull(packageDependencies, nameof(packageDependencies));
|
||||
Requires.NotNullOrEmpty(packageLockFile, nameof(packageLockFile));
|
||||
Requires.NotNullOrEmpty(packagesDirectory, nameof(packagesDirectory));
|
||||
Requires.NotNullOrEmpty(platform, nameof(platform));
|
||||
Requires.NotNullOrEmpty(projectFullPath, nameof(projectFullPath));
|
||||
Requires.NotNullOrEmpty(projectName, nameof(projectName));
|
||||
Requires.NotNull(projectReferences, nameof(projectReferences));
|
||||
Requires.NotNullOrEmpty(rootNamespace, nameof(rootNamespace));
|
||||
Requires.NotNullOrEmpty(runtimeConfigJson, nameof(runtimeConfigJson));
|
||||
Requires.NotNullOrEmpty(targetDirectory, nameof(targetDirectory));
|
||||
Requires.NotNull(targetFramework, nameof(targetFramework));
|
||||
|
||||
AssemblyFullPath = assemblyFullPath;
|
||||
AssemblyName = assemblyName;
|
||||
CompilationAssemblies = compilationAssemblies;
|
||||
CompilationItems = compilationItems;
|
||||
Config = config;
|
||||
Configuration = configuration;
|
||||
DepsJson = depsJson;
|
||||
EmbededItems = embededItems;
|
||||
IsClassLibrary = isClassLibrary;
|
||||
PackageDependencies = packageDependencies;
|
||||
PackageLockFile = packageLockFile;
|
||||
PackagesDirectory = packagesDirectory;
|
||||
Platform = platform;
|
||||
ProjectFullPath = projectFullPath;
|
||||
ProjectName = projectName;
|
||||
ProjectReferences = projectReferences;
|
||||
RootNamespace = rootNamespace;
|
||||
RuntimeConfigJson = runtimeConfigJson;
|
||||
TargetDirectory = targetDirectory;
|
||||
TargetFramework = targetFramework;
|
||||
}
|
||||
public string AssemblyFullPath { get; }
|
||||
|
||||
public string AssemblyName { get; }
|
||||
|
||||
public IEnumerable<ResolvedReference> CompilationAssemblies { get; }
|
||||
|
||||
public IEnumerable<string> CompilationItems { get; }
|
||||
|
||||
public string Config { get; }
|
||||
|
||||
public string Configuration { get; }
|
||||
|
||||
public string DepsJson { get; }
|
||||
|
||||
public IEnumerable<string> EmbededItems { get; }
|
||||
|
||||
public bool IsClassLibrary { get; }
|
||||
|
||||
public IEnumerable<DependencyDescription> PackageDependencies { get; }
|
||||
|
||||
public string PackageLockFile { get; }
|
||||
|
||||
public string PackagesDirectory { get; }
|
||||
|
||||
public string Platform { get; }
|
||||
|
||||
public string ProjectFullPath { get; }
|
||||
|
||||
public string ProjectName { get; }
|
||||
|
||||
public IEnumerable<string> ProjectReferences { get; }
|
||||
|
||||
public string RootNamespace { get; }
|
||||
|
||||
public string RuntimeConfigJson { get; }
|
||||
|
||||
public string TargetDirectory { get; }
|
||||
|
||||
public NuGetFramework TargetFramework { get; }
|
||||
|
||||
public string FindProperty(string propertyName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.VisualStudio.Web.CodeGeneration.Msbuild")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("84d9af9f-1aa5-4041-a983-33f28a075395")]
|
|
@ -0,0 +1,29 @@
|
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!--<Import Project="$(Project)" />-->
|
||||
<UsingTask TaskName="_WriteProjectReferences"
|
||||
AssemblyFile="$(MSBuildThisFileDirectory)\..\..\tools\Microsoft.VisualStudio.Web.CodeGeneration.MsBuild.dll" />
|
||||
<PropertyGroup>
|
||||
<_WriteProjectReferencesDependsOn>
|
||||
$(_WriteProjectReferenceDependsOn);
|
||||
ResolveReferences;
|
||||
ResolvePackageDependenciesDesignTime;
|
||||
</_WriteProjectReferencesDependsOn>
|
||||
</PropertyGroup>
|
||||
<Target Name="_WriteProjectReferences" DependsOnTargets="$(_WriteProjectRferencesDependsOn)">
|
||||
|
||||
<WriteProjectReferenceInformation Framework ="$(TargetFramework)"
|
||||
OutputFile ="$(OutputFile)"
|
||||
Name ="$(ProjectName)"
|
||||
ResolvedReferences ="@(ReferencePath)"
|
||||
PackageDependencies ="@(_DependenciesDesignTime)"
|
||||
ProjectReferences ="@(ProjectReference)"
|
||||
AssemblyFullPath ="$(TargetPath)"
|
||||
PackagesDirectory="$(NuGetPackageRoot)"
|
||||
OutputType="$(OutputType)"
|
||||
Platform="$(Platform)"
|
||||
RootNameSpace ="$(RootNamespace)"
|
||||
CompilationItems ="@(Compile)"
|
||||
TargetDirectory="$(TargetDir)"/>
|
||||
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,186 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Extensions.ProjectModel.Resolution;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.Web.CodeGeneration.Utils;
|
||||
|
||||
namespace Microsoft.VisualStudio.Web.CodeGeneration.Msbuild
|
||||
{
|
||||
public class WriteReferencesToFile : Build.Utilities.Task
|
||||
{
|
||||
#region Inputs
|
||||
[Build.Framework.Required]
|
||||
public string OutputFile { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public ITaskItem[] ResolvedReferences { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public ITaskItem[] PackageDependencies { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public ITaskItem[] ProjectReferences { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public ITaskItem[] CompilationItems { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public ITaskItem[] EmbeddedItems { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string TargetFramework { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string OutputType { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string PackagesDirectory { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string Platform { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string TargetDirectory { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string RootNamespace { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string AssemblyFullPath { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string AssemblyName { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string Configuration { get; set; }
|
||||
|
||||
[Build.Framework.Required]
|
||||
public string ProjectFullPath { get; set; }
|
||||
#endregion
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
var msBuildContext = new MsBuildProjectContext(
|
||||
assemblyFullPath: AssemblyFullPath,
|
||||
assemblyName: AssemblyName,
|
||||
compilationAssemblies: GetCompilationAssemblies(ResolvedReferences),
|
||||
compilationItems: CompilationItems.Select(i => i.ItemSpec),
|
||||
config: "Debug",
|
||||
configuration: Configuration,
|
||||
depsJson: "...",
|
||||
embededItems: EmbeddedItems.Select(i => i.ItemSpec),
|
||||
isClassLibrary: "Library".Equals(OutputType, StringComparison.OrdinalIgnoreCase),
|
||||
packageDependencies: GetPackageDependencies(PackageDependencies),
|
||||
packageLockFile: "packagelockfile",
|
||||
packagesDirectory: PackagesDirectory,
|
||||
platform: Platform,
|
||||
projectFullPath: ProjectFullPath,
|
||||
projectName: Name,
|
||||
projectReferences: ProjectReferences.Select(i => i.ItemSpec),
|
||||
rootNamespace: RootNamespace,
|
||||
runtimeConfigJson: "runtimeConfigJson",
|
||||
targetDirectory: TargetDirectory,
|
||||
targetFramework: NuGet.Frameworks.NuGetFramework.Parse(TargetFramework));
|
||||
|
||||
using(var streamWriter = new StreamWriter(File.Create(OutputFile)))
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(msBuildContext);
|
||||
streamWriter.Write(json);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<DependencyDescription> GetPackageDependencies(ITaskItem[] packageDependecyItems)
|
||||
{
|
||||
Requires.NotNull(packageDependecyItems, nameof(packageDependecyItems));
|
||||
var packages = packageDependecyItems.Select(item => new { key = item.ItemSpec, value = GetPackageDependency(item) })
|
||||
.Where(package => package != null && package.value != null);
|
||||
var packageMap = new Dictionary<string, DependencyDescription>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach(var package in packages)
|
||||
{
|
||||
packageMap.Add(package.key, package.value);
|
||||
}
|
||||
|
||||
PopulateDependencies(packageMap, packageDependecyItems);
|
||||
|
||||
return packageMap.Values;
|
||||
}
|
||||
|
||||
private void PopulateDependencies(Dictionary<string, DependencyDescription> packageMap, ITaskItem[] packageDependecyItems)
|
||||
{
|
||||
Requires.NotNull(packageMap, nameof(packageMap));
|
||||
Requires.NotNull(packageDependecyItems, nameof(packageDependecyItems));
|
||||
|
||||
foreach (var item in packageDependecyItems)
|
||||
{
|
||||
var depSpecs = item.GetMetadata("Dependencies")
|
||||
?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
DependencyDescription current = null;
|
||||
if (depSpecs == null || !packageMap.TryGetValue(item.GetMetadata("ItemSpec"), out current))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var depSpec in depSpecs)
|
||||
{
|
||||
var spec = item.GetMetadata("ItemSpec").Split('/').FirstOrDefault() + depSpec;
|
||||
DependencyDescription d = null;
|
||||
if (packageMap.TryGetValue(spec, out d))
|
||||
{
|
||||
current.AddDependency(new Dependency(d.Name, d.Version));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DependencyDescription GetPackageDependency(ITaskItem item)
|
||||
{
|
||||
Requires.NotNull(item, nameof(item));
|
||||
|
||||
var type = item.GetMetadata("Type");
|
||||
var name = ("Target".Equals(type, StringComparison.OrdinalIgnoreCase))
|
||||
? item.ItemSpec
|
||||
: item.GetMetadata("Name");
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var version = item.GetMetadata("Version");
|
||||
var path = item.GetMetadata("Path");
|
||||
var resolved = item.GetMetadata("Resolved");
|
||||
|
||||
var isResolved = false;
|
||||
bool.TryParse(resolved, out isResolved);
|
||||
|
||||
var framework = item.ItemSpec.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).First();
|
||||
|
||||
return new DependencyDescription(name, version, path, framework, type, isResolved);
|
||||
}
|
||||
|
||||
private IEnumerable<ResolvedReference> GetCompilationAssemblies(ITaskItem[] resolvedReferences)
|
||||
{
|
||||
Requires.NotNull(resolvedReferences, nameof(resolvedReferences));
|
||||
var compilationAssemblies = new List<ResolvedReference>();
|
||||
foreach (var item in resolvedReferences)
|
||||
{
|
||||
var resolvedPath = item.ItemSpec;
|
||||
var name = Path.GetFileName(resolvedPath);
|
||||
var reference = new ResolvedReference(name, resolvedPath);
|
||||
compilationAssemblies.Add(reference);
|
||||
}
|
||||
|
||||
return compilationAssemblies;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"compile": {
|
||||
"include": "../Shared/**/*.cs"
|
||||
},
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.Build.Runtime": "15.1.319-preview5",
|
||||
"Microsoft.Extensions.ProjectModel.Abstractions.Sources": {
|
||||
"version": "1.0.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"NETStandard.Library": "1.6.0-*",
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"NuGet.Frameworks": "3.6.0-*"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.6": {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,8 @@
|
|||
"version": "1.0.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Newtonsoft.Json": "9.0.1"
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"NuGet.ProjectModel": "3.6.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
|
@ -55,7 +56,7 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.1.0-*",
|
||||
"version": "1.0.0-*",
|
||||
"type": "platform"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,14 @@ namespace Microsoft.VisualStudio.Web.CodeGeneration
|
|||
[Fact]
|
||||
public void GetAliasAttribute_Returns_Correct_Value()
|
||||
{
|
||||
//TODO @prbhosal Fix this test
|
||||
////Arrange
|
||||
//MemberInfo testType = typeof(ClassWithAlias);
|
||||
//Arrange
|
||||
MemberInfo testType = typeof(ClassWithAlias).GetTypeInfo();
|
||||
|
||||
////Act
|
||||
//var attribute = testType.GetAliasAttribute();
|
||||
//Act
|
||||
var attribute = testType.GetAliasAttribute();
|
||||
|
||||
////Assert
|
||||
//Assert.Equal("CoolClass", attribute.Alias);
|
||||
//Assert
|
||||
Assert.Equal("CoolClass", attribute.Alias);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -13,6 +13,7 @@ using Microsoft.VisualStudio.Web.CodeGeneration.Utils;
|
|||
using Moq;
|
||||
using NuGet.Frameworks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.Test
|
||||
{
|
||||
|
@ -27,6 +28,12 @@ namespace Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.Test
|
|||
private CodeAnalysis.Workspace _workspace;
|
||||
private ILogger _logger;
|
||||
private ProjectInformation _projectInformation;
|
||||
private ITestOutputHelper _output;
|
||||
|
||||
public EntityFrameworkServicesTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
|
||||
private EntityFrameworkServices GetEfServices(string path, string applicationName)
|
||||
{
|
||||
|
@ -35,7 +42,7 @@ namespace Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.Test
|
|||
_packageInstaller = new Mock<IPackageInstaller>();
|
||||
_serviceProvider = new Mock<IServiceProvider>();
|
||||
|
||||
_projectInformation = GetProjectInformation(path, false);
|
||||
_projectInformation = GetProjectInformation(path);
|
||||
_workspace = new RoslynWorkspace(_projectInformation);
|
||||
_loader = new TestAssemblyLoadContext(_projectInformation.RootProject);
|
||||
_modelTypesLocator = new ModelTypesLocator(_workspace);
|
||||
|
@ -69,55 +76,78 @@ namespace Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.Test
|
|||
|
||||
}
|
||||
|
||||
private ProjectInformation GetProjectInformation(string path, bool isMsBuild)
|
||||
private ProjectInformation GetProjectInformation(string path)
|
||||
{
|
||||
if (isMsBuild)
|
||||
{
|
||||
var rootContext = new MsBuildProjectContextBuilder()
|
||||
.AsDesignTimeBuild()
|
||||
.WithTargetFramework(FrameworkConstants.CommonFrameworks.NetCoreApp10)
|
||||
.WithConfiguration("Debug")
|
||||
.Build();
|
||||
// TODO needs to be fixed to get all dependent Projects as well.
|
||||
return new ProjectInformation(rootContext, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
var context = Microsoft.DotNet.ProjectModel.ProjectContext.Create(path, FrameworkConstants.CommonFrameworks.NetStandard16);
|
||||
var dotnetContext = new DotNetProjectContext(context, "Debug", null);
|
||||
var dependencyProjectContexts = new List<Microsoft.DotNet.ProjectModel.ProjectContext>();
|
||||
foreach (var dependency in dotnetContext.ProjectReferences)
|
||||
{
|
||||
var dependencyContext = Microsoft.DotNet.ProjectModel.ProjectContext.Create(dependency, FrameworkConstants.CommonFrameworks.NetStandard16);
|
||||
dependencyProjectContexts.Add(dependencyContext);
|
||||
}
|
||||
|
||||
return new ProjectInformation(dotnetContext,
|
||||
dependencyProjectContexts.Select(d => new DotNetProjectContext(d, "Debug", null)));
|
||||
}
|
||||
var rootContext = new MsBuildProjectContextBuilder()
|
||||
.AsDesignTimeBuild()
|
||||
.WithTargetFramework(FrameworkConstants.CommonFrameworks.NetCoreApp10)
|
||||
.WithConfiguration("Debug")
|
||||
.Build();
|
||||
// TODO needs to be fixed to get all dependent Projects as well.
|
||||
return new ProjectInformation(rootContext, null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void TestGetModelMetadata_WithoutDbContext()
|
||||
{
|
||||
var appName = "ModelTypesLocatorTestClassLibrary";
|
||||
var path = Path.Combine(Directory.GetCurrentDirectory(), "..", "TestApps", appName);
|
||||
var efServices = GetEfServices(path, appName);
|
||||
var modelType = _modelTypesLocator.GetType("ModelWithMatchingShortName").First();
|
||||
var metadata = await efServices.GetModelMetadata(modelType);
|
||||
Assert.Equal(ContextProcessingStatus.ContextAvailable, metadata.ContextProcessingStatus);
|
||||
Assert.Null(metadata.ModelMetadata.Navigations);
|
||||
Assert.False(metadata.ModelMetadata.Properties.Any());
|
||||
using (var fileProvider = new TemporaryFileProvider())
|
||||
{
|
||||
SetupProjects(fileProvider);
|
||||
|
||||
modelType = _modelTypesLocator.GetType("ModelTypesLocatorTestClassLibrary.Car").First();
|
||||
metadata = await efServices.GetModelMetadata(modelType);
|
||||
Assert.Equal(ContextProcessingStatus.ContextAvailable, metadata.ContextProcessingStatus);
|
||||
Assert.Null(metadata.ModelMetadata.Navigations);
|
||||
Assert.Null(metadata.ModelMetadata.PrimaryKeys);
|
||||
Assert.Equal(3, metadata.ModelMetadata.Properties.Length);
|
||||
var appName = "ModelTypesLocatorTestClassLibrary";
|
||||
var path = Path.Combine(Directory.GetCurrentDirectory(), "..", "TestApps", appName);
|
||||
var efServices = GetEfServices(path, appName);
|
||||
var modelType = _modelTypesLocator.GetType("ModelWithMatchingShortName").First();
|
||||
var metadata = await efServices.GetModelMetadata(modelType);
|
||||
Assert.Equal(ContextProcessingStatus.ContextAvailable, metadata.ContextProcessingStatus);
|
||||
Assert.Null(metadata.ModelMetadata.Navigations);
|
||||
Assert.False(metadata.ModelMetadata.Properties.Any());
|
||||
|
||||
modelType = _modelTypesLocator.GetType("Library1.Models.Car").First();
|
||||
metadata = await efServices.GetModelMetadata(modelType);
|
||||
Assert.Equal(ContextProcessingStatus.ContextAvailable, metadata.ContextProcessingStatus);
|
||||
Assert.Null(metadata.ModelMetadata.Navigations);
|
||||
Assert.Null(metadata.ModelMetadata.PrimaryKeys);
|
||||
Assert.Equal(3, metadata.ModelMetadata.Properties.Length);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact/*(Skip ="Need to update workspace creation for this to work.")*/]
|
||||
private void SetupProjects(TemporaryFileProvider fileProvider)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Root"));
|
||||
Directory.CreateDirectory(Path.Combine(fileProvider.Root, "Library1"));
|
||||
fileProvider.Add("Nuget.config", MsBuildProjectStrings.NugetConfigTxt);
|
||||
|
||||
fileProvider.Add($"Root/{MsBuildProjectStrings.RootProjectName}", MsBuildProjectStrings.RootProjectTxt);
|
||||
fileProvider.Add($"Root/Startup.cs", MsBuildProjectStrings.StartupTxt);
|
||||
|
||||
fileProvider.Add($"Library1/{MsBuildProjectStrings.LibraryProjectName}", MsBuildProjectStrings.LibraryProjectTxt);
|
||||
fileProvider.Add($"Library1/ModelWithMatchingShortName.cs", "namespace Library1.Models { public class ModelWithMatchingShortName { } }");
|
||||
fileProvider.Add($"Library1/Car.cs", @"namespace Library1.Models
|
||||
{
|
||||
public class Car
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int ManufacturerID { get; set; }
|
||||
public Manufacturer Manufacturer { get; set; }
|
||||
}
|
||||
|
||||
public class Manufacturer
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public virtual ICollection<Car> Cars { get; set; }
|
||||
}
|
||||
}");
|
||||
var result = Command.CreateDotNet("restore3",
|
||||
new[] { Path.Combine(fileProvider.Root, "Root", "test.csproj") })
|
||||
.OnErrorLine(l => _output.WriteLine(l))
|
||||
.OnOutputLine(l => _output.WriteLine(l))
|
||||
.Execute();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void TestGetModelMetadata_WithDbContext()
|
||||
{
|
||||
var appName = "ModelTypesLocatorTestWebApp";
|
||||
|
@ -130,21 +160,5 @@ namespace Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.Test
|
|||
Assert.Equal(ContextProcessingStatus.ContextAvailable, metadata.ContextProcessingStatus);
|
||||
Assert.Equal(3, metadata.ModelMetadata.Properties.Length);
|
||||
}
|
||||
|
||||
private int BuildProject(string project)
|
||||
{
|
||||
var args = new List<string>()
|
||||
{
|
||||
project,
|
||||
"--configuration", "Debug"
|
||||
};
|
||||
var command = Command.CreateDotNet(
|
||||
"build",
|
||||
args);
|
||||
|
||||
var result = command.Execute();
|
||||
|
||||
return result.ExitCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
{
|
||||
"buildOptions": {
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
"keyFile": "../../tools/Key.snk",
|
||||
"compile": {
|
||||
"include": "../Shared/**/*.cs"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"dotnet-test-xunit": "2.2.0-*",
|
||||
|
|
Загрузка…
Ссылка в новой задаче