Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving patch fixes from placeholder branch to rel/2.0.1 #626

Merged
merged 13 commits into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ public int Execute(Action<IEnumerable<FileSystemChangeInformation>> simModeActio
AddFrameworkServices(serviceProvider, _projectInformation);
AddCodeGenerationServices(serviceProvider);
var codeGenCommand = serviceProvider.GetService<CodeGenCommand>();
codeGenCommand.Execute(_codeGenArguments);

if (_isSimulationMode && simModeAction != null)
try
{
simModeAction.Invoke(SimulationModeFileSystem.Instance.FileSystemChanges);
codeGenCommand.Execute(_codeGenArguments);

if (_isSimulationMode && simModeAction != null)
{
simModeAction.Invoke(SimulationModeFileSystem.Instance.FileSystemChanges);
}
}
catch (InvalidOperationException ioe)
{
_logger.LogMessage(ioe.Message, LogMessageLevel.Error);
_logger.LogMessage(ioe.StackTrace, LogMessageLevel.Trace);
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<!--
NOTE: Do not add package/ project references to this file.
Edit the Shared.proj file to add additional package/ project references.
-->
<Import Project="Shared.props" />
<PropertyGroup>
<Description>Code Generation tool for ASP.NET Core. Contains the dotnet-aspnet-codegenerator command used for generating controllers and views.</Description>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<AssemblyName>dotnet-aspnet-codegenerator-design</AssemblyName>
<OutputType>exe</OutputType>
<PackageTags>aspnetcore;codegenerator;scaffolding;visualstudioweb</PackageTags>
<PackageId>Microsoft.VisualStudio.Web.CodeGeneration.Design</PackageId>
<RuntimeIdentifier Condition=" '$(TargetFramework)' != 'netcoreapp2.0' ">win7-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$(TargetFramework)' != 'netcoreapp2.0' ">win7-x64</RuntimeIdentifier>
<X86ProjectDirectory>..\..\tools\Microsoft.VisualStudio.Web.CodeGeneration.Design-x86\</X86ProjectDirectory>
<ARMProjectDirectory>..\..\tools\Microsoft.VisualStudio.Web.CodeGeneration.Design-arm\</ARMProjectDirectory>
<ARM64ProjectDirectory>..\..\tools\Microsoft.VisualStudio.Web.CodeGeneration.Design-arm64\</ARM64ProjectDirectory>
<AnyCpuProjectDirectory>..\..\tools\Microsoft.VisualStudio.Web.CodeGeneration.Design-anycpu\</AnyCpuProjectDirectory>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<ProjectReference Include="$(X86ProjectDirectory)\Microsoft.VisualStudio.Web.CodeGeneration.Design-x86.csproj" PrivateAssets="true" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(ARMProjectDirectory)\Microsoft.VisualStudio.Web.CodeGeneration.Design-arm.csproj" PrivateAssets="true" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(ARM64ProjectDirectory)\Microsoft.VisualStudio.Web.CodeGeneration.Design-arm64.csproj" PrivateAssets="true" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(AnyCpuProjectDirectory)\Microsoft.VisualStudio.Web.CodeGeneration.Design-anycpu.csproj" PrivateAssets="true" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.VisualStudio.Web.CodeGenerators.Mvc\Microsoft.VisualStudio.Web.CodeGenerators.Mvc.csproj" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
<None Include="$(OutputPath)netcoreapp2.0\$(AssemblyName).dll" Pack="true" PackagePath="lib\netcoreapp2.0\$(AssemblyName).dll" />
<None Include="$(OutputPath)netcoreapp2.0\$(AssemblyName).xml" Pack="true" PackagePath="lib\netcoreapp2.0\$(AssemblyName).xml" />
</ItemGroup>

<ItemGroup Condition="'$(OS)'=='Windows_NT'">
<None Include="$(OutputPath)net461\win7-x64\$(AssemblyName).exe" Pack="true" PackagePath="runtimes\win7-x64\native\$(AssemblyName).exe" />
<None Include="$(OutputPath)net461\win7-x64\$(AssemblyName).xml" Pack="true" PackagePath="runtimes\win7-x64\native\$(AssemblyName).xml" />
<None Include="$(X86ProjectDirectory)\bin\$(Configuration)\net461\win7-x86\$(AssemblyName).exe" Pack="true" PackagePath="runtimes\win7-x86\native\$(AssemblyName).exe" />
<None Include="$(X86ProjectDirectory)\bin\$(Configuration)\net461\win7-x86\$(AssemblyName).xml" Pack="true" PackagePath="runtimes\win7-x86\native\$(AssemblyName).xml" />
<None Include="$(ARMProjectDirectory)\bin\$(Configuration)\net461\win-arm\$(AssemblyName).exe" Pack="true" PackagePath="runtimes\win-arm\native\$(AssemblyName).exe" />
<None Include="$(ARMProjectDirectory)\bin\$(Configuration)\net461\win-arm\$(AssemblyName).xml" Pack="true" PackagePath="runtimes\win-arm\native\$(AssemblyName).xml" />
<None Include="$(ARM64ProjectDirectory)\bin\$(Configuration)\net461\win-arm64\$(AssemblyName).exe" Pack="true" PackagePath="runtimes\win-arm64\native\$(AssemblyName).exe" />
<None Include="$(ARM64ProjectDirectory)\bin\$(Configuration)\net461\win-arm64\$(AssemblyName).xml" Pack="true" PackagePath="runtimes\win-arm64\native\$(AssemblyName).xml" />
<None Include="$(AnyCpuProjectDirectory)\bin\$(Configuration)\net461\$(AssemblyName).exe" Pack="true" PackagePath="lib\net461\$(AssemblyName).exe" />
<None Include="$(AnyCpuProjectDirectory)\bin\$(Configuration)\net461\$(AssemblyName).xml" Pack="true" PackagePath="lib\net461\$(AssemblyName).xml" />
</ItemGroup>

<!--<ItemGroup>
Expand Down
59 changes: 37 additions & 22 deletions src/Microsoft.VisualStudio.Web.CodeGeneration.Design/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,50 @@ private static void Execute(string[] args, ConsoleLogger logger)
#endif
app.OnExecute(async () =>
{
CodeGenerationEnvironmentHelper.SetupEnvironment();
string project = projectPath.Value();
if (string.IsNullOrEmpty(project))
var exitCode = 1;
try
{
project = Directory.GetCurrentDirectory();
}
project = Path.GetFullPath(project);
var configuration = appConfiguration.Value();
CodeGenerationEnvironmentHelper.SetupEnvironment();
string project = projectPath.Value();
if (string.IsNullOrEmpty(project))
{
project = Directory.GetCurrentDirectory();
}
project = Path.GetFullPath(project);
var configuration = appConfiguration.Value();

var portNumber = int.Parse(port.Value());
using (var client = await ScaffoldingClient.Connect(portNumber, logger))
{
var messageOrchestrator = new MessageOrchestrator(client, logger);
var projectInformation = messageOrchestrator.GetProjectInformation();
var portNumber = int.Parse(port.Value());
using (var client = await ScaffoldingClient.Connect(portNumber, logger))
{
var messageOrchestrator = new MessageOrchestrator(client, logger);
var projectInformation = messageOrchestrator.GetProjectInformation();

var codeGenArgs = ToolCommandLineHelper.FilterExecutorArguments(args);
var isSimulationMode = ToolCommandLineHelper.IsSimulationMode(args);
CodeGenCommandExecutor executor = new CodeGenCommandExecutor(projectInformation,
codeGenArgs,
configuration,
logger,
isSimulationMode);
var codeGenArgs = ToolCommandLineHelper.FilterExecutorArguments(args);
var isSimulationMode = ToolCommandLineHelper.IsSimulationMode(args);
CodeGenCommandExecutor executor = new CodeGenCommandExecutor(projectInformation,
codeGenArgs,
configuration,
logger,
isSimulationMode);

var exitCode = executor.Execute((changes) => messageOrchestrator.SendFileSystemChangeInformation(changes));
exitCode = executor.Execute((changes) => messageOrchestrator.SendFileSystemChangeInformation(changes));

messageOrchestrator.SendScaffoldingCompletedMessage();
messageOrchestrator.SendScaffoldingCompletedMessage();
}
}
catch(Exception ex)
{
logger.LogMessage(Resources.GenericErrorMessage, LogMessageLevel.Error);
logger.LogMessage(ex.Message, LogMessageLevel.Error);
logger.LogMessage(ex.StackTrace, LogMessageLevel.Trace);
if (!logger.IsTracing)
{
logger.LogMessage(Resources.EnableTracingMessage);
}

return exitCode;
}
return exitCode;

});

app.Execute(args);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,15 @@
<data name="ConnectToServerError" xml:space="preserve">
<value>Could not connect to port {0}.</value>
</data>
<data name="EnableTracingMessage" xml:space="preserve">
<value>To see more information, enable tracing by setting environment variable 'codegen_trace' = 1.</value>
</data>
<data name="FileSystemChangeMessageNotSupported" xml:space="preserve">
<value>Server does not support File System change messages. HostId: '{0}', ProtocolVersion: '{1}'.</value>
</data>
<data name="GenericErrorMessage" xml:space="preserve">
<value>Scaffolding failed.</value>
</data>
<data name="ProjectInformationError" xml:space="preserve">
<value>Could not get ProjectInformation.</value>
</data>
Expand Down
17 changes: 17 additions & 0 deletions src/Microsoft.VisualStudio.Web.CodeGeneration.Design/Shared.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>Code Generation tool for ASP.NET Core. Contains the dotnet-aspnet-codegenerator command used for generating controllers and views.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<AssemblyName>dotnet-aspnet-codegenerator-design</AssemblyName>
<OutputType>exe</OutputType>
<RootNamespace>Microsoft.VisualStudio.Web.CodeGeneration.Design</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\Microsoft.VisualStudio.Web.CodeGenerators.Mvc\Microsoft.VisualStudio.Web.CodeGenerators.Mvc.csproj" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
</ItemGroup>

</Project>
89 changes: 63 additions & 26 deletions src/Microsoft.VisualStudio.Web.CodeGeneration.Tools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,53 @@ public static void Main(string[] args)
/// 1. Try getting the projectContext for the project
/// 2. Invoke project dependency command with the first compatible tfm found in the project
/// </summary>
private static void Execute(string[] args, bool isNoBuild, ILogger logger)
private static void Execute(string[] args, bool isNoBuild, ConsoleLogger logger)
{
var app = new ScaffoldingApp(false);

app.OnExecute(() =>
{
string project = app.ProjectPath.Value();
if (string.IsNullOrEmpty(project))
try
{
project = Directory.GetCurrentDirectory();
string project = app.ProjectPath.Value();
if (string.IsNullOrEmpty(project))
{
project = Directory.GetCurrentDirectory();
}

project = Path.GetFullPath(project);
var configuration = app.AppConfiguration.Value() ?? "Debug";

var projectFileFinder = new ProjectFileFinder(project);

if (ToolCommandLineHelper.IsHelpArgument(args)
|| app.GeneratorArgument == null
|| string.IsNullOrEmpty(app.GeneratorArgument.Value))
{
app.ProjectContext = GetProjectInformation(projectFileFinder.ProjectFilePath, configuration);
app.ShowHelp();
return 0;
}
// Invoke the tool from the project's build directory.
return BuildAndDispatchDependencyCommand(
args,
projectFileFinder.ProjectFilePath,
app.BuildBasePath.Value(),
configuration,
isNoBuild,
logger);
}

project = Path.GetFullPath(project);
var configuration = app.AppConfiguration.Value() ?? "Debug";

var projectFileFinder = new ProjectFileFinder(project);

if (ToolCommandLineHelper.IsHelpArgument(args))
catch (Exception ex)
{
app.ProjectContext = GetProjectInformation(projectFileFinder.ProjectFilePath, configuration);
app.ShowHelp();
return 0;
logger.LogMessage(Resources.GenericErrorMessage, LogMessageLevel.Error);
logger.LogMessage(ex.Message, LogMessageLevel.Error);
logger.LogMessage(ex.StackTrace, LogMessageLevel.Trace);
if (!logger.IsTracing)
{
logger.LogMessage(Resources.EnableTracingMessage);
}
return -1;
}
// Invoke the tool from the project's build directory.
return BuildAndDispatchDependencyCommand(
args,
projectFileFinder.ProjectFilePath,
app.BuildBasePath.Value(),
configuration,
isNoBuild,
logger);

});

Expand Down Expand Up @@ -166,15 +182,27 @@ private static Command CreateDipatchCommand(
var runtimeConfigPath = Path.Combine(targetDir, context.RuntimeConfig);
var depsFile = Path.Combine(targetDir, context.DepsFile);

string dotnetCodeGenInsideManPath = context.CompilationAssemblies
string dotnetCodeGenInsideManPath = string.Empty;

if (IsNetCoreAppFramework(frameworkToUse))
{
dotnetCodeGenInsideManPath = context.CompilationAssemblies
.Where(c => Path.GetFileNameWithoutExtension(c.Name)
.Equals(DESIGN_TOOL_NAME, StringComparison.OrdinalIgnoreCase))
.Select(reference => reference.ResolvedPath)
.FirstOrDefault();

if (string.IsNullOrEmpty(dotnetCodeGenInsideManPath))
if (string.IsNullOrEmpty(dotnetCodeGenInsideManPath))
{
throw new InvalidOperationException(Resources.AddDesignPackage);
}
}
else
{
throw new InvalidOperationException(Resources.AddDesignPackage);
dotnetCodeGenInsideManPath = Path.Combine(Path.GetDirectoryName(context.AssemblyFullPath), DESIGN_TOOL_NAME + ".exe");
if (!File.Exists(dotnetCodeGenInsideManPath))
{
throw new InvalidOperationException(Resources.AddDesignPackage);
}
}

var dependencyArgs = ToolCommandLineHelper.GetProjectDependencyCommandArgs(
Expand All @@ -193,6 +221,15 @@ private static Command CreateDipatchCommand(
assemblyFullPath: context.AssemblyFullPath);
}

private static bool IsNetCoreAppFramework(NuGetFramework framework)
{
// Only need to compare the framework name to be netcoreapp. Version doesn't matter.

return NuGetFramework.FrameworkNameComparer.Equals(
framework,
NuGet.Frameworks.FrameworkConstants.CommonFrameworks.NetCoreApp10);
}

private static IProjectContext GetProjectInformation(string projectPath, string configuration)
{
var projectFileFinder = new ProjectFileFinder(projectPath);
Expand Down
Loading