Exemplo n.º 1
0
        public TemplateTestBase(ITestOutputHelper output)
        {
            _output.Value = output;
            TemplatePackageInstaller.EnsureTemplatingEngineInitialized(output);

            ProjectGuid = Guid.NewGuid().ToString("N");
            ProjectName = $"AspNet.Template.{ProjectGuid}";

            var assemblyPath = GetType().GetTypeInfo().Assembly.CodeBase;
            var assemblyUri  = new Uri(assemblyPath, UriKind.Absolute);
            var basePath     = Path.GetDirectoryName(assemblyUri.LocalPath);

            TemplateOutputDir = Path.Combine(basePath, "TestTemplates", ProjectName);
            Directory.CreateDirectory(TemplateOutputDir);

            // We don't want any of the host repo's build config interfering with
            // how the test project is built, so disconnect it from the
            // Directory.Build.props/targets context

            var templatesTestsPropsFilePath = Path.Combine(basePath, "TemplateTests.props");
            var directoryBuildPropsContent  =
                $@"<Project>
    <Import Project=""Directory.Build.After.props"" Condition=""Exists('Directory.Build.After.props')"" />
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.props"), directoryBuildPropsContent);
            var directoryBuildTargetsContent =
                $@"<Project>
    <Import Project=""{templatesTestsPropsFilePath}"" />
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent);
        }
Exemplo n.º 2
0
        public Project CreateProject(ITestOutputHelper output)
        {
            TemplatePackageInstaller.EnsureTemplatingEngineInitialized(output);
            var project = new Project
            {
                DotNetNewLock = DotNetNewLock,
                Output        = output,
                ProjectGuid   = Guid.NewGuid().ToString("N").Substring(0, 6)
            };

            project.ProjectName = $"AspNet.Template.{project.ProjectGuid}";

            _projects.Add(project);

            var assemblyPath = GetType().GetTypeInfo().Assembly.CodeBase;
            var assemblyUri  = new Uri(assemblyPath, UriKind.Absolute);
            var basePath     = Path.GetDirectoryName(assemblyUri.LocalPath);

            project.TemplateOutputDir = Path.Combine(basePath, "TestTemplates", project.ProjectName);
            Directory.CreateDirectory(project.TemplateOutputDir);

            // We don't want any of the host repo's build config interfering with
            // how the test project is built, so disconnect it from the
            // Directory.Build.props/targets context

            var templatesTestsPropsFilePath = Path.Combine(basePath, "TemplateTests.props");
            var directoryBuildPropsContent  =
                $@"<Project>
    <Import Project=""Directory.Build.After.props"" Condition=""Exists('Directory.Build.After.props')"" />
</Project>";

            File.WriteAllText(Path.Combine(project.TemplateOutputDir, "Directory.Build.props"), directoryBuildPropsContent);

            // TODO: remove this once we get a newer version of the SDK which supports an implicit FrameworkReference
            // cref https://github.com/aspnet/websdk/issues/424
            var directoryBuildTargetsContent =
                $@"<Project>
    <Import Project=""{templatesTestsPropsFilePath}"" />
</Project>";

            File.WriteAllText(Path.Combine(project.TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent);

            return(project);
        }
Exemplo n.º 3
0
        public TemplateTestBase(ITestOutputHelper output)
        {
            _output.Value = output;
            TemplatePackageInstaller.EnsureTemplatingEngineInitialized(output);

            ProjectGuid = Guid.NewGuid().ToString("N");
            ProjectName = $"AspNet.Template.{ProjectGuid}";

            var assemblyPath = GetType().GetTypeInfo().Assembly.CodeBase;
            var assemblyUri  = new Uri(assemblyPath, UriKind.Absolute);
            var basePath     = Path.GetDirectoryName(assemblyUri.LocalPath);

            TemplateOutputDir = Path.Combine(basePath, "TestTemplates", ProjectName);
            Directory.CreateDirectory(TemplateOutputDir);

            // We don't want any of the host repo's build config interfering with
            // how the test project is built, so disconnect it from the
            // Directory.Build.props/targets context

            var templatesTestsPropsFilePath = Path.Combine(basePath, "TemplateTests.props");
            var directoryBuildPropsContent  =
                $@"<Project>
    <Import Project=""Directory.Build.After.props"" Condition=""Exists('Directory.Build.After.props')"" />
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.props"), directoryBuildPropsContent);

            // TODO: remove this once we get a newer version of the SDK which supports an implicit FrameworkReference
            // cref https://github.com/aspnet/websdk/issues/424
            var directoryBuildTargetsContent =
                $@"<Project>
    <Import Project=""{templatesTestsPropsFilePath}"" />

    <ItemGroup>
       <FrameworkReference Remove=""Microsoft.AspNetCore.App"" />
       <PackageReference Include=""Microsoft.AspNetCore.App"" Version=""$(BundledAspNetCoreAppPackageVersion)"" IsImplicitlyDefined=""true"" />
    </ItemGroup>
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent);
        }