Example #1
0
        public static Uri GetIISUrl(this IUseCsProjFile proj)
        {
            if (File.Exists(proj.LaunchSettingsJsonPath))
            {
                var launchSettings = JsonSerializer.Deserialize <Root>(File.ReadAllText(proj.LaunchSettingsJsonPath));
                var iisExpress     = launchSettings?.iisSettings?.iisExpress;
                if (iisExpress is not iisExpress settings)
                {
                    throw new InvalidOperationException("Expected path launchSettings.iisSettings.iisExpress not found or empty.");
                }
                var originalUri = settings.applicationUrl;
                if (originalUri is not Uri u)
                {
                    throw new InvalidOperationException("iisExpress.applicationUrl must not be empty");
                }
                var builder = new UriBuilder(u)
                {
                    Port   = settings.sslPort != 0 ? settings.sslPort : originalUri.Port,
                    Scheme = settings.sslPort != 0 ? Uri.UriSchemeHttps : originalUri.Scheme
                };
                return(builder.Uri);
            }

            var(nav, nsMan, nsPrefix) = proj.CreateNavigator();
Example #2
0
        private static (XPathNavigator navigator, XmlNamespaceManager nsManager, string nsPrefix) CreateNavigator(this IUseCsProjFile proj)
        {
            if (proj == null)
            {
                throw new ArgumentNullException(nameof(proj));
            }
            var          xp    = new XPathDocument(proj.FullPath);
            var          nav   = xp.CreateNavigator();
            var          nsman = new XmlNamespaceManager(new NameTable());
            const string mns   = "m:";

            nsman.AddNamespace(mns.Replace(":", ""), MsBuildNs);
            return(nav, nsman, mns);
        }
Example #3
0
 public static string GetProjName(this IUseCsProjFile proj) => Path.GetFileNameWithoutExtension(proj.FullPath);
Example #4
0
        public static (string framework, string runtime) GetTargetFrameworkAndRuntime(this IUseCsProjFile proj)
        {
            if (proj == null)
            {
                throw new ArgumentNullException(nameof(proj));
            }
            var xp = new XPathDocument(proj.FullPath);
            var n  = xp.CreateNavigator();
            var tf = n.SelectSingleNode("/Project/PropertyGroup/TargetFramework");

            if (tf == null)
            {
                throw new InvalidOperationException($"TargetFramework is not defined in {proj.FullPath}");
            }

            var ri = n.SelectSingleNode("/Project/PropertyGroup/RuntimeIdentifier");

            return(framework : tf.Value, runtime : ri?.Value);
        }
Example #5
0
 public static string GetWorkingDir(this IUseCsProjFile proj) =>
 new FileInfo(proj.FullPath).DirectoryName
 ?? throw new InvalidOperationException($"Path '{proj.FullPath}' doesn't have directory name");