Exemplo n.º 1
0
        public void DnuPublishWebApp_SubdirAsPublicDir_DirPlusFlatList(DnxSdk sdk)
        {
            const string projectName = "ProjectForTesting";

            FrameworkName[] frameworkCandidates =
            {
                FrameworkNameHelper.ParseFrameworkName("dnx451"),
                FrameworkNameHelper.ParseFrameworkName("dnxcore50")
            };

            var targetFramework = DependencyContext.SelectFrameworkNameForRuntime(
                frameworkCandidates, sdk.FullName).FullName;

            var projectJson = new JObject
            {
                ["publishExclude"] = "**.useless",
                ["webroot"]        = "public",
                ["frameworks"]     = new JObject
                {
                    ["dnx451"]    = new JObject {
                    },
                    ["dnxcore50"] = new JObject {
                    }
                }
            };

            var projectStructure = new Dir
            {
Exemplo n.º 2
0
        public static CompilationSettings GetCompilationSettings(this Project project, string frameworkName)
        {
            var framework = FrameworkNameHelper.ParseFrameworkName(frameworkName);

            return(project.GetCompilerOptions(framework, "Debug")
                   .ToCompilationSettings(framework));
        }
Exemplo n.º 3
0
        private static UiPackageDependencySet LoadDependencySet(JObject set)
        {
            var fxName = set.Value <string>(Properties.TargetFramework);

            return(new UiPackageDependencySet(
                       String.IsNullOrEmpty(fxName) ? null : FrameworkNameHelper.ParsePossiblyShortenedFrameworkName(fxName),
                       (set.Value <JArray>(Properties.Dependencies) ?? Enumerable.Empty <JToken>()).Select(obj => LoadDependency((JObject)obj))));
        }
Exemplo n.º 4
0
        private void TestGetNearestPicksMostCompatibleItem(string input, string frameworks, string expected)
        {
            var inputFx    = FrameworkNameHelper.ParseFrameworkName(input);
            var fxs        = frameworks.Split(',').Select(VersionUtility.ParseFrameworkName).ToArray();
            var expectedFx = VersionUtility.ParseFrameworkName(expected);

            var actual = VersionUtility.GetNearest(inputFx, fxs);

            Assert.Equal(expectedFx, actual);
        }
Exemplo n.º 5
0
 public void AddFrameworkMonikers(IEnumerable <string> monikers)
 {
     if (monikers != null)
     {
         foreach (var moniker in monikers.Distinct())
         {
             TargetFrameworks.Add(FrameworkNameHelper.ParseFrameworkName(moniker), moniker);
         }
     }
 }
Exemplo n.º 6
0
        public void CompilerOptionsAreSetPerConfiguration()
        {
            var project = Project.GetProject(@"
{
    ""frameworks"" : {
        ""net45"":  {
            ""compilationOptions"": { ""allowUnsafe"": true, ""define"": [""X"", ""y""], ""platform"": ""x86"", ""warningsAsErrors"": true }
        },
        ""dnx451"": {
        },
        ""dnxcore50"": {
            ""compilationOptions"": { ""define"": [""X""], ""warningsAsErrors"": true }
        },
        ""k10"": {
            ""compilationOptions"": { ""warningsAsErrors"": true }
        }
    }
}",
                                             "foo",
                                             @"c:\foo\project.json");

            var compilerOptions = project.GetCompilerOptions();

            Assert.NotNull(compilerOptions);
            var net45Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("net45"));

            Assert.NotNull(net45Options);
            Assert.True(net45Options.AllowUnsafe.Value);
            Assert.Equal(new[] { "X", "y", "NET45" }, net45Options.Defines);
            Assert.True(net45Options.WarningsAsErrors.Value);
            Assert.Equal("x86", net45Options.Platform);

            var dnx451Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("dnx451"));

            Assert.NotNull(dnx451Options);
            Assert.Equal(new[] { "DNX451" }, dnx451Options.Defines);
            Assert.Null(dnx451Options.AllowUnsafe);

            var aspnetCore50Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("dnxcore50"));

            Assert.NotNull(aspnetCore50Options);
            Assert.Equal(new[] { "X", "DNXCORE50" }, aspnetCore50Options.Defines);
            Assert.True(aspnetCore50Options.WarningsAsErrors.Value);

            var k10Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("k10"));

            Assert.NotNull(k10Options);
            Assert.Null(k10Options.AllowUnsafe);
            Assert.Equal(new[] { "K10" }, k10Options.Defines);
            Assert.True(k10Options.WarningsAsErrors.Value);
            Assert.Null(k10Options.Platform);
        }
Exemplo n.º 7
0
        public static FrameworkName GetFrameworkForRuntimeFlavor(string flavor)
        {
            if (string.Equals("clr", flavor, StringComparison.OrdinalIgnoreCase) ||
                string.Equals("mono", flavor, StringComparison.OrdinalIgnoreCase))
            {
                return(FrameworkNameHelper.ParseFrameworkName("dnx451"));
            }
            else if (string.Equals("coreclr", flavor, StringComparison.OrdinalIgnoreCase))
            {
                return(FrameworkNameHelper.ParseFrameworkName("dnxcore50"));
            }

            throw new InvalidOperationException($"Unknown runtime flavor '{flavor}'");
        }
Exemplo n.º 8
0
        public void GetCompilerOptionsCombinesConfigurationAndTargetFrameworkfNotNull()
        {
            // Arrange
            var project         = Project.GetProject(_projectContent, "TestProj", "project.json");
            var targetFramework = FrameworkNameHelper.ParseFrameworkName("dnxcore50");

            // Act
            var options = project.GetCompilerOptions(targetFramework, configurationName: "Debug");

            // Assert
            Assert.Equal(new[] { "GLOBAL", "TEST_DEBUG", "XYZ", "TEST_ASPNETCORE", "DNXCORE50" }, options.Defines);
            Assert.Equal(true, options.WarningsAsErrors);
            Assert.Equal(true, options.AllowUnsafe);
            Assert.Equal("x86", options.Platform);
        }
Exemplo n.º 9
0
        public void GetCompilerOptionsCombinesTargetFrameworkIfNotNull()
        {
            // Arrange
            var project         = Project.GetProject(_projectContent, "TestProj", "project.json");
            var targetFramework = FrameworkNameHelper.ParseFrameworkName("dnx451");

            // Act
            var options = project.GetCompilerOptions(targetFramework, configurationName: null);

            // Assert
            Assert.Equal(new[] { "GLOBAL", "TEST_DNX451", "DNX451" }, options.Defines);
            Assert.Equal(true, options.WarningsAsErrors);
            Assert.Null(options.AllowUnsafe);
            Assert.Equal("x86", options.Platform);
        }
Exemplo n.º 10
0
        public void GetCompilerOptionsGeneratesTFMDefineForShortName(string tfm, string define)
        {
            // Arrange
            var projectContent  = @"{ ""frameworks"": { """ + tfm + @""": {} } }";
            var project         = ProjectUtilities.GetProject(projectContent, "TestProj", "project.json");
            var targetFramework = FrameworkNameHelper.ParseFrameworkName(tfm);

            // Act
            var options = project.GetCompilerOptions(targetFramework, configurationName: "Debug");

            // Assert
            var expectedDefines = define == null ? new[] { "DEBUG", "TRACE" } : new[] { "DEBUG", "TRACE", define };

            Assert.Equal(expectedDefines, options.Defines);
        }
Exemplo n.º 11
0
        private async Task <IEnumerable <VisualStudioUISearchMetadata> > Search(int startIndex, CancellationToken ct)
        {
            if (_option.Filter == Filter.Installed ||
                _option.Filter == Filter.UpdatesAvailable)
            {
                // search in target
                var packages = await _target.SearchInstalled(
                    _source,
                    _searchText,
                    startIndex,
                    _pageSize,
                    ct);

                return(packages.Select(p => CreateResult(p)));
            }
            else
            {
                // search in source
                if (_source == null)
                {
                    return(Enumerable.Empty <VisualStudioUISearchMetadata>());
                }
                else
                {
                    // TODO: hacky code to get SourceRepo2. Will be removed later.
                    var s             = ServiceLocator.GetInstance <VsPackageManagerContext>();
                    var sourceManager = s.SourceManager as VsSourceRepositoryManager;
                    var repo2         = sourceManager.CreateRepo2(_source.Source);

                    var searchFilter = new SearchFilter();
                    searchFilter.SupportedFrameworks = _target.GetSupportedFrameworks()
                                                       .Select(fn => FrameworkNameHelper.GetShortFrameworkName(fn));
                    searchFilter.IncludePrerelease = _option.IncludePrerelease;

                    var search = await repo2.GetResource <IVisualStudioUISearch>();

                    return(await search.GetSearchResultsForVisualStudioUI(
                               _searchText,
                               searchFilter,
                               startIndex,
                               _pageSize,
                               ct));
                }
            }
        }
Exemplo n.º 12
0
        public void GetDescriptionReturnsCorrectResults(string name, string version, string framework, bool found)
        {
            var libraryRange = new LibraryRange(name, frameworkReference: true)
            {
                VersionRange = VersionUtility.ParseVersionRange(version)
            };

            var frameworkName = FrameworkNameHelper.ParseFrameworkName(framework);
            var resolver      = new GacDependencyResolver();
            var library       = resolver.GetDescription(libraryRange, frameworkName);

            if (found)
            {
                Assert.NotNull(library);
                Assert.Equal(SemanticVersion.Parse(version), library.Identity.Version);
            }
            else
            {
                Assert.Null(library);
            }
        }
Exemplo n.º 13
0
 public void CorrectlyParsesFrameworkNames(string input, string fullName)
 {
     Assert.Equal(
         new FrameworkName(fullName),
         FrameworkNameHelper.ParseFrameworkName(input));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Parse a Json object which represents project configuration for a specified framework
        /// </summary>
        /// <param name="frameworkKey">The name of the framework</param>
        /// <param name="frameworkValue">The Json object represent the settings</param>
        /// <returns>Returns true if it successes.</returns>
        private bool BuildTargetFrameworkNode(Project project, string frameworkKey, JsonObject frameworkValue)
        {
            // If no compilation options are provided then figure them out from the node
            var compilerOptions = GetCompilationOptions(frameworkValue) ??
                                  new CompilerOptions();

            var frameworkName = FrameworkNameHelper.ParseFrameworkName(frameworkKey);

            // If it's not unsupported then keep it
            if (frameworkName == VersionUtility.UnsupportedFrameworkName)
            {
                // REVIEW: Should we skip unsupported target frameworks
                return(false);
            }

            // Add the target framework specific define
            var defines             = new HashSet <string>(compilerOptions.Defines ?? Enumerable.Empty <string>());
            var frameworkDefinition = Tuple.Create(frameworkKey, frameworkName);
            var frameworkDefine     = FrameworkNameHelper.MakeDefaultTargetFrameworkDefine(frameworkDefinition);

            if (!string.IsNullOrEmpty(frameworkDefine))
            {
                defines.Add(frameworkDefine);
            }

            compilerOptions.Defines = defines;

            var targetFrameworkInformation = new TargetFrameworkInformation
            {
                FrameworkName = frameworkName,
                Dependencies  = new List <LibraryDependency>()
            };

            var frameworkDependencies = new List <LibraryDependency>();

            PopulateDependencies(
                project.ProjectFilePath,
                frameworkDependencies,
                frameworkValue,
                "dependencies",
                isGacOrFrameworkReference: false);

            var frameworkAssemblies = new List <LibraryDependency>();

            PopulateDependencies(
                project.ProjectFilePath,
                frameworkAssemblies,
                frameworkValue,
                "frameworkAssemblies",
                isGacOrFrameworkReference: true);

            frameworkDependencies.AddRange(frameworkAssemblies);
            targetFrameworkInformation.Dependencies = frameworkDependencies;

            targetFrameworkInformation.WrappedProject = frameworkValue.ValueAsString("wrappedProject");

            var binNode = frameworkValue.ValueAsJsonObject("bin");

            if (binNode != null)
            {
                targetFrameworkInformation.AssemblyPath = binNode.ValueAsString("assembly");
                targetFrameworkInformation.PdbPath      = binNode.ValueAsString("pdb");
            }

            project._compilerOptionsByFramework[frameworkName] = compilerOptions;
            project._targetFrameworks[frameworkName]           = targetFrameworkInformation;

            return(true);
        }