Updated common.targets to use AssemblyName instead of MSBuildProjectName so renaming output assembly from csproj works

Fixes https://github.com/aspnet/Mvc/issues/5780
This commit is contained in:
Roderic Bos 2017-02-10 10:24:37 +01:00 committed by Pranav K
parent 95cf0f48ff
commit 3c14472bf2
11 changed files with 154 additions and 5 deletions

View File

@ -1,6 +1,5 @@
<Project>
<PropertyGroup>
</PropertyGroup>
<Import Project="dependencies.props" />
<ItemGroup>
<PackageReference Include="Internal.AspNetCore.Sdk" Version="1.0.1-*" PrivateAssets="All" />

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))</_MvcRazorOutputPath>
<_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath)</_MvcRazorOutputPath>
<_MvcRazorOutputFullPath>$(_MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.dll</_MvcRazorOutputFullPath>
<_MvcRazorOutputFullPath>$(_MvcRazorOutputPath)$(AssemblyName).PrecompiledViews.dll</_MvcRazorOutputFullPath>
<_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp</_MvcRazorResponseFilePath>
<MvcRazorContentRoot Condition="'$(MvcRazorContentRoot)'==''">$(MSBuildProjectDirectory)</MvcRazorContentRoot>
@ -21,7 +21,7 @@
<ExecArgs Include="
$(MSBuildProjectDirectory);
--output-path=$(_MvcRazorOutputPath);
--application-name=$(MSBuildProjectName);
--application-name=$(AssemblyName);
--content-root=$(MvcRazorContentRoot);" />
<ExecArgs

View File

@ -0,0 +1,2 @@
AspNetCore._Views_Home_Index_cshtml, NewAssemblyName.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

View File

@ -0,0 +1,55 @@
// 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.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
{
public class SimpleAppWithAssemblyRenameTest : IClassFixture<SimpleAppWithAssemblyRenameTest.SimpleAppWithAssemblyRenameTestFixture>
{
public SimpleAppWithAssemblyRenameTest(SimpleAppWithAssemblyRenameTestFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[Theory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
{
// Arrange
using (var deployer = Fixture.CreateDeployment(flavor))
{
var deploymentResult = deployer.Deploy();
// Act
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
deploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("SimpleAppWithAssemblyRenameTest.Home.Index.txt", response);
}
}
public class SimpleAppWithAssemblyRenameTestFixture : ApplicationTestFixture
{
public SimpleAppWithAssemblyRenameTestFixture()
: base("SimpleAppWithAssemblyRename")
{
}
public override DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor)
{
var parameters = base.GetDeploymentParameters(flavor);
parameters.ApplicationName = "NewAssemblyName";
return parameters;
}
}
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
namespace SimpleAppWithAssemblyRename.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}

View File

@ -0,0 +1,26 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace SimpleAppWithAssemblyRename
{
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'RazorViewCompilation.sln'))\build\common-testapps.props" />
<PropertyGroup>
<AssemblyName>NewAssemblyName</AssemblyName>
<TargetFrameworks>netcoreapp1.1;net451</TargetFrameworks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<OutputType>Exe</OutputType>
<RuntimeIdentifier Condition="!$(TargetFramework.StartsWith('netcoreapp'))">win7-x64</RuntimeIdentifier>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation">
<Version>1.2.0-*</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.2.0-*" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.2.0-*" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.2.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.2.0-*" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace SimpleAppWithAssemblyRename
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
app.UseMvcWithDefaultRoute();
}
}
}

View File

@ -0,0 +1,5 @@
@{
ViewData["Title"] = "Home Page";
}
@GetType().AssemblyQualifiedName

View File

@ -0,0 +1,2 @@
@using SimpleAppWithAssemblyRename
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26014.0
VisualStudioVersion = 15.0.26206.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{43488AEE-CCF2-4A90-B890-05320282BE29}"
ProjectSection(SolutionItems) = preProject
@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StrongNamedApp", "StrongNam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleAppDesktopOnly", "SimpleAppDesktopOnly\SimpleAppDesktopOnly.csproj", "{A0B0A141-A32B-4F33-B85F-5CA8C107105F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleAppWithAssemblyRename", "SimpleAppWithAssemblyRename\SimpleAppWithAssemblyRename.csproj", "{3AAF7A48-333C-4D1A-A12B-A3B77DEADF4B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -57,6 +59,10 @@ Global
{A0B0A141-A32B-4F33-B85F-5CA8C107105F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0B0A141-A32B-4F33-B85F-5CA8C107105F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0B0A141-A32B-4F33-B85F-5CA8C107105F}.Release|Any CPU.Build.0 = Release|Any CPU
{3AAF7A48-333C-4D1A-A12B-A3B77DEADF4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AAF7A48-333C-4D1A-A12B-A3B77DEADF4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AAF7A48-333C-4D1A-A12B-A3B77DEADF4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AAF7A48-333C-4D1A-A12B-A3B77DEADF4B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE