Esempio n. 1
0
        public void SetProjectRootFolder(FSharpOption <string> rootFolder)
        {
            var tempDirectory = DetermineDirectoryForTestProjects();

            if (rootFolder.IsSome())
            {
                tempDirectory = Path.Combine(tempDirectory, rootFolder.Value);
            }

            _solutionFolder = Path.Combine(tempDirectory, "Project_" + ProjectGuid.ToString("D"));
        }
        private string BuildClassLibrayProject(string projectNamespace)
        {
            string contents = EmbeddedResource.ConvertStreamResourceToString(typeof(ClassLibrary), "Chucksoft.Entities.Templates.ClassLibraryProject.template");

            contents = contents.Replace("<%[ProjectGuid]%>", ProjectGuid.ToString());
            contents = contents.Replace("<%[RootNamespace]%>", projectNamespace);
            contents = contents.Replace("<%[AssemblyName]%>", projectNamespace);
            contents = contents.Replace("<%[ProjectClasses]%>", GenerateFiles());

            return(contents);
        }
Esempio n. 3
0
        private string BuildClassLibrayProject(string projectNamespace)
        {
            string contents = Core.ResourceFileHelper.ConvertStreamResourceToUTF8String(typeof(CodeGenSettings), "Chucksoft.Entities.Templates.ClassLibraryProject.template");

            if (string.IsNullOrEmpty(contents))
            {
                throw new ContentNotFound("Can't find embeddedResource \"Chucksoft.Entities.Templates.ClassLibraryProject.template\"");
            }

            contents = contents.Replace("<%[ProjectGuid]%>", ProjectGuid.ToString());
            contents = contents.Replace("<%[RootNamespace]%>", projectNamespace);
            contents = contents.Replace("<%[AssemblyName]%>", projectNamespace);
            contents = contents.Replace("<%[ProjectClasses]%>", GenerateFiles());

            return(contents);
        }
Esempio n. 4
0
        public override void SaveProject(string filepath)
        {
            var writer = XmlWriter.Create(filepath, new XmlWriterSettings()
            {
                Indent = true, IndentChars = "\t"
            });

            writer.WriteStartDocument();
            writer.WriteStartElement("Project");
            writer.WriteAttributeString("Name", ProjName);
            writer.WriteAttributeString("ToolVersion", ToolVer);
            writer.WriteAttributeString("GameVersion", GameVer);
            writer.WriteAttributeString("Platform", Enum.GetName(typeof(ProjPlatform), Platform));
            writer.WriteStartElement("ProjectGUID");
            writer.WriteString(ProjectGuid.ToString());
            writer.WriteEndElement();
            writer.WriteStartElement("FileGroup");
            foreach (var item in Includes.Where(x => x.IsDirectory))
            {
                writer.WriteStartElement("Folder");
                writer.WriteAttributeString("Include", item.RelativePath);
                writer.WriteEndElement();
            }
            // Dont need to write new start and
            // end element unless we structurally
            // seperate included files from folders
            writer.WriteEndElement();

            writer.WriteStartElement("FileGroup");
            foreach (var item in Includes.Where(x => !x.IsDirectory))
            {
                writer.WriteStartElement("Content");
                writer.WriteAttributeString("Include", item.RelativePath);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteEndDocument();
            writer.Close();
            var doc = new XmlDocument();

            doc.Load(filepath);
            ProjFile = doc;
        }
Esempio n. 5
0
        internal string GetText()
        {
            var builder = new StringBuilder();

            builder.AppendFormat("Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\"", ProjectTypeGuid.ToString("B").ToUpper(), ProjectName, ProjectPath, ProjectGuid.ToString("B").ToUpper());
            builder.AppendLine();

            foreach (var block in _projectSections)
            {
                builder.Append(block.GetText(indent: 1));
            }

            builder.AppendLine("EndProject");

            return(builder.ToString());
        }
Esempio n. 6
0
        public XDocument GetXML()
        {
            var sampleCSProjPath = (Type == ProjectStyle.PackageReference && ToolingVersion15) ?
                                   "Test.Utility.compiler.resources.project2.csproj" :
                                   "Test.Utility.compiler.resources.project1.csproj";

            var s   = ResourceTestUtility.GetResource(sampleCSProjPath, typeof(SimpleTestProjectContext));
            var xml = XDocument.Parse(s);

            //  MSBuildProjectExtensionsPath needs to be set before Microsoft.Common.props is imported, so add a new
            //  PropertyGroup as the first element under the Project
            var ns = xml.Root.GetDefaultNamespace();

            if (SetMSBuildProjectExtensionsPath)
            {
                var propertyGroup = new XElement(ns + "PropertyGroup");
                propertyGroup.Add(new XElement(ns + "MSBuildProjectExtensionsPath", OutputPath));
                xml.Root.AddFirst(propertyGroup);
            }

            ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
            {
                { "ProjectGuid", "{" + ProjectGuid.ToString() + "}" },
                { "AssemblyName", ProjectName }
            });

            ProjectFileUtils.AddProperties(xml, Properties);

            if (Type == ProjectStyle.PackageReference)
            {
                if (WarningsAsErrors)
                {
                    ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
                    {
                        { "WarningsAsErrors", "true" }
                    });
                }

                ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
                {
                    { "Version", Version },
                    { "DebugType", "portable" }
                });

                if (!IsLegacyPackageReference)
                {
                    var tfPropName = SingleTargetFramework ? "TargetFramework" : "TargetFrameworks";

                    ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
                    {
                        { tfPropName, OriginalFrameworkStrings.Count != 0 ? string.Join(";", OriginalFrameworkStrings):
                          string.Join(";", Frameworks.Select(f => f.Framework.GetShortFolderName())) },
                    });
                }

                var addedToAllProjectReferences = new HashSet <SimpleTestProjectContext>();
                var addedToAllPackageReferences = new HashSet <SimpleTestPackageContext>();
                var addedToAllPackageDownloads  = new HashSet <SimpleTestPackageContext>();

                foreach (var frameworkInfo in Frameworks)
                {
                    // Add properties with a TFM condition
                    ProjectFileUtils.AddProperties(xml, frameworkInfo.Properties, $" '$(TargetFramework)' == '{frameworkInfo.Framework.GetShortFolderName()}' ");

                    foreach (var package in frameworkInfo.PackageReferences)
                    {
                        var referenceFramework = frameworkInfo.Framework;

                        // Drop the conditional if it is not needed
                        if (Frameworks.All(f => f.PackageReferences.Contains(package)))
                        {
                            referenceFramework = NuGetFramework.AnyFramework;

                            if (!addedToAllPackageReferences.Add(package))
                            {
                                // Skip since this was already added
                                continue;
                            }
                        }

                        var props      = new Dictionary <string, string>();
                        var attributes = new Dictionary <string, string>();

                        // To support CPVM scenarios the Version can be null
                        // In these cases do not write any version
                        if (package.Version != null)
                        {
                            if (ToolingVersion15)
                            {
                                attributes.Add("Version", package.Version.ToString());
                            }
                            else
                            {
                                props.Add("Version", package.Version.ToString());
                            }
                        }

                        if (!string.IsNullOrEmpty(package.Include))
                        {
                            props.Add("IncludeAssets", package.Include);
                        }

                        if (!string.IsNullOrEmpty(package.Exclude))
                        {
                            props.Add("ExcludeAssets", package.Exclude);
                        }

                        if (!string.IsNullOrEmpty(package.PrivateAssets))
                        {
                            props.Add("PrivateAssets", package.PrivateAssets);
                        }

                        if (!string.IsNullOrEmpty(package.Aliases))
                        {
                            props.Add("Aliases", package.Aliases);
                        }

                        if (!string.IsNullOrEmpty(package.NoWarn))
                        {
                            props.Add("NoWarn", package.NoWarn);
                        }

                        ProjectFileUtils.AddItem(
                            xml,
                            "PackageReference",
                            package.Id,
                            referenceFramework,
                            props,
                            attributes);
                    }

                    foreach (var package in frameworkInfo.PackageDownloads)
                    {
                        var referenceFramework = frameworkInfo.Framework;

                        // Drop the conditional if it is not needed
                        if (Frameworks.All(f => f.PackageDownloads.Contains(package)))
                        {
                            referenceFramework = NuGetFramework.AnyFramework;

                            if (!addedToAllPackageDownloads.Add(package))
                            {
                                // Skip since this was already added
                                continue;
                            }
                        }

                        var props      = new Dictionary <string, string>();
                        var attributes = new Dictionary <string, string>();

                        props.Add("Version", $"[{package.Version.ToString()}]");

                        ProjectFileUtils.AddItem(
                            xml,
                            "PackageDownload",
                            package.Id,
                            referenceFramework,
                            props,
                            attributes);
                    }


                    foreach (var project in frameworkInfo.ProjectReferences)
                    {
                        var referenceFramework = frameworkInfo.Framework;

                        // Drop the conditional if it is not needed
                        if (Frameworks.All(f => f.ProjectReferences.Contains(project)))
                        {
                            referenceFramework = NuGetFramework.AnyFramework;

                            if (!addedToAllProjectReferences.Add(project))
                            {
                                // Skip since this was already added
                                continue;
                            }
                        }

                        var props = new Dictionary <string, string>
                        {
                            { "Name", project.ProjectName },
                            { "Project", project.ProjectGuid.ToString() }
                        };

                        if (!string.IsNullOrEmpty(project.ExcludeAssets))
                        {
                            props.Add("IncludeAssets", project.ExcludeAssets);
                        }

                        if (!string.IsNullOrEmpty(project.ExcludeAssets))
                        {
                            props.Add("ExcludeAssets", project.ExcludeAssets);
                        }

                        if (!string.IsNullOrEmpty(project.PrivateAssets))
                        {
                            props.Add("PrivateAssets", project.PrivateAssets);
                        }

                        ProjectFileUtils.AddItem(
                            xml,
                            "ProjectReference",
                            $"{project.ProjectPath}",
                            referenceFramework,
                            props,
                            new Dictionary <string, string>());
                    }
                }

                // Add tool references
                foreach (var tool in DotnetCLIToolReferences)
                {
                    var props      = new Dictionary <string, string>();
                    var attributes = new Dictionary <string, string>();

                    if (ToolingVersion15)
                    {
                        attributes.Add("Version", tool.Version.ToString());
                    }
                    else
                    {
                        props.Add("Version", tool.Version.ToString());
                    }

                    ProjectFileUtils.AddItem(
                        xml,
                        "DotNetCliToolReference",
                        $"{tool.Id}",
                        NuGetFramework.AnyFramework,
                        props,
                        attributes);
                }
            }
            else
            {
                // Add all project references directly
                foreach (var project in Frameworks.SelectMany(f => f.ProjectReferences).Distinct())
                {
                    var props = new Dictionary <string, string>
                    {
                        { "Name", project.ProjectName },
                        { "Project", project.ProjectGuid.ToString() }
                    };

                    if (!string.IsNullOrEmpty(project.ExcludeAssets))
                    {
                        props.Add("IncludeAssets", project.ExcludeAssets);
                    }

                    if (!string.IsNullOrEmpty(project.ExcludeAssets))
                    {
                        props.Add("ExcludeAssets", project.ExcludeAssets);
                    }

                    if (!string.IsNullOrEmpty(project.PrivateAssets))
                    {
                        props.Add("PrivateAssets", project.PrivateAssets);
                    }

                    ProjectFileUtils.AddItem(
                        xml,
                        "ProjectReference",
                        $"{project.ProjectPath}",
                        NuGetFramework.AnyFramework,
                        props,
                        new Dictionary <string, string>());
                }
            }

            return(xml);
        }
Esempio n. 7
0
        public override void SaveTo(string projectPath)
        {
            var projectDir = Path.GetDirectoryName(projectPath);

            var msBuildProject = MsBuild.Construction.ProjectRootElement.Create();

            try
            {
                msBuildProject.ToolsVersion   = "4.0";
                msBuildProject.DefaultTargets = "Build";

                {
                    try
                    {
                        var propertyGroup = msBuildProject.AddPropertyGroup();
                        propertyGroup.AddProperty("ProjectGuid", ProjectGuid.ToString("B").ToUpper());
                        propertyGroup.AppendChild(CreateProperty(msBuildProject, "Configuration", "Debug", " '$(Configuration)' == '' "));
                        propertyGroup.AppendChild(CreateProperty(msBuildProject, "Platform", "x86", " '$(Platform)' == '' "));
                        propertyGroup.AddProperty("OutputType", "Library");
                        propertyGroup.AddProperty("RootNamespace", "VVVV.Nodes");
                        propertyGroup.AddProperty("AssemblyName", AssemblyName);
                        propertyGroup.AddProperty("TargetFrameworkVersion", "v4.0");
                        propertyGroup.AddProperty("OutputPath", @"bin\$(Platform)\$(Configuration)\");
                        propertyGroup.AddProperty("AllowUnsafeBlocks", "True");

                        //add loaded reference paths
                        var referencePaths = ReferencePaths.Select(refPath =>
                                                                   Path.IsPathRooted(refPath)
                                ? PathUtils.MakeRelativePath(projectDir + @"\", refPath + @"\")
                                : refPath);
                        var referencePathValue = string.Join(";", referencePaths);
                        if (!string.IsNullOrEmpty(referencePathValue))
                        {
                            propertyGroup.AddProperty("ReferencePath", referencePathValue);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                // From src/Default.Project.settings
                {
                    var propertyGroup = msBuildProject.AddPropertyGroup();
                    propertyGroup.Condition = " '$(Configuration)' == 'Debug' ";
                    propertyGroup.AddProperty("DefineConstants", "DEBUG;TRACE");
                    propertyGroup.AddProperty("Optimize", "False");
                    propertyGroup.AddProperty("CheckForOverflowUnderflow", "True");
                    propertyGroup.AddProperty("DebugType", "Full");
                    propertyGroup.AddProperty("DebugSymbols", "True");
                }

                {
                    var propertyGroup = msBuildProject.AddPropertyGroup();
                    propertyGroup.Condition = " '$(Configuration)' == 'Release' ";
                    propertyGroup.AddProperty("DefineConstants", "TRACE");
                    propertyGroup.AddProperty("Optimize", "True");
                    propertyGroup.AddProperty("CheckForOverflowUnderflow", "False");
                    propertyGroup.AddProperty("DebugType", "None");
                    propertyGroup.AddProperty("DebugSymbols", "False");
                }

                {
                    var propertyGroup = msBuildProject.AddPropertyGroup();
                    propertyGroup.Condition = " '$(Platform)' == 'AnyCPU' ";
                    propertyGroup.AddProperty("PlatformTarget", "AnyCPU");
                }

                {
                    var propertyGroup = msBuildProject.AddPropertyGroup();
                    propertyGroup.Condition = " '$(Platform)' == 'x86' ";
                    propertyGroup.AddProperty("PlatformTarget", "x86");
                }

                {
                    var propertyGroup = msBuildProject.AddPropertyGroup();
                    propertyGroup.Condition = " '$(Platform)' == 'x64' ";
                    propertyGroup.AddProperty("PlatformTarget", "x64");
                }

                //add referenced items
                foreach (var reference in References)
                {
                    var item = msBuildProject.AddItem("Reference", reference.Name);
                    if (!reference.IsGlobal && !InReferencePaths(reference.Name))
                    {
                        var hintPath = reference.GetRelativePath();
                        var dsc      = Path.DirectorySeparatorChar;
                        hintPath = hintPath.Replace(dsc + "x86" + dsc, dsc + "$(Platform)");
                        hintPath = hintPath.Replace(dsc + "x64" + dsc, dsc + "$(Platform)");
                        item.AddMetadata("HintPath", hintPath);
                    }
                }

                foreach (var document in Documents)
                {
                    msBuildProject.AddItem(document.CanBeCompiled ? "Compile" : "None", document.GetRelativePath());
                }

                msBuildProject.AddImport("$(MSBuildBinPath)\\Microsoft.CSharp.Targets");

                // Create the project directory if it doesn't exist yet.
                if (!Directory.Exists(projectDir))
                {
                    Directory.CreateDirectory(projectDir);
                }

                msBuildProject.Save(projectPath);
            }
            finally
            {
                MsBuild.Evaluation.ProjectCollection.GlobalProjectCollection.UnloadProject(msBuildProject);
            }

            base.SaveTo(projectPath);
        }
        public XDocument GetXML()
        {
            var sampleCSProjPath = (Type == ProjectStyle.PackageReference && ToolingVersion15) ?
                                   "Test.Utility.compiler.resources.project2.csproj" :
                                   "Test.Utility.compiler.resources.project1.csproj";

            var s   = ResourceTestUtility.GetResource(sampleCSProjPath, typeof(SimpleTestProjectContext));
            var xml = XDocument.Parse(s);

            ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
            {
                { "ProjectGuid", "{" + ProjectGuid.ToString() + "}" },
                { "BaseIntermediateOutputPath", OutputPath },
                { "AssemblyName", ProjectName }
            });

            ProjectFileUtils.AddProperties(xml, Properties);

            if (Type == ProjectStyle.PackageReference)
            {
                if (WarningsAsErrors)
                {
                    ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
                    {
                        { "WarningsAsErrors", "true" }
                    });
                }

                ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
                {
                    { "Version", Version },
                    { "DebugType", "portable" }
                });

                if (!IsLegacyPackageReference)
                {
                    var tfPropName = SingleTargetFramework ? "TargetFramework" : "TargetFrameworks";

                    ProjectFileUtils.AddProperties(xml, new Dictionary <string, string>()
                    {
                        { tfPropName, OriginalFrameworkStrings.Count != 0 ? string.Join(";", OriginalFrameworkStrings):
                          string.Join(";", Frameworks.Select(f => f.Framework.GetShortFolderName())) },
                    });
                }

                var addedToAllProjectReferences = new HashSet <SimpleTestProjectContext>();
                var addedToAllPackageReferences = new HashSet <SimpleTestPackageContext>();

                foreach (var frameworkInfo in Frameworks)
                {
                    // Add properties with a TFM condition
                    ProjectFileUtils.AddProperties(xml, frameworkInfo.Properties, $" '$(TargetFramework)' == '{frameworkInfo.Framework.GetShortFolderName()}' ");

                    foreach (var package in frameworkInfo.PackageReferences)
                    {
                        var referenceFramework = frameworkInfo.Framework;

                        // Drop the conditional if it is not needed
                        if (Frameworks.All(f => f.PackageReferences.Contains(package)))
                        {
                            referenceFramework = NuGetFramework.AnyFramework;

                            if (!addedToAllPackageReferences.Add(package))
                            {
                                // Skip since this was already added
                                continue;
                            }
                        }

                        var props      = new Dictionary <string, string>();
                        var attributes = new Dictionary <string, string>();

                        if (ToolingVersion15)
                        {
                            attributes.Add("Version", package.Version.ToString());
                        }
                        else
                        {
                            props.Add("Version", package.Version.ToString());
                        }

                        if (!string.IsNullOrEmpty(package.Include))
                        {
                            props.Add("IncludeAssets", package.Include);
                        }

                        if (!string.IsNullOrEmpty(package.Exclude))
                        {
                            props.Add("ExcludeAssets", package.Exclude);
                        }

                        if (!string.IsNullOrEmpty(package.PrivateAssets))
                        {
                            props.Add("PrivateAssets", package.PrivateAssets);
                        }

                        if (!string.IsNullOrEmpty(package.NoWarn))
                        {
                            props.Add("NoWarn", package.NoWarn);
                        }

                        ProjectFileUtils.AddItem(
                            xml,
                            "PackageReference",
                            package.Id,
                            referenceFramework,
                            props,
                            attributes);
                    }

                    foreach (var project in frameworkInfo.ProjectReferences)
                    {
                        var referenceFramework = frameworkInfo.Framework;

                        // Drop the conditional if it is not needed
                        if (Frameworks.All(f => f.ProjectReferences.Contains(project)))
                        {
                            referenceFramework = NuGetFramework.AnyFramework;

                            if (!addedToAllProjectReferences.Add(project))
                            {
                                // Skip since this was already added
                                continue;
                            }
                        }

                        var props = new Dictionary <string, string>
                        {
                            { "Name", project.ProjectName },
                            { "Project", project.ProjectGuid.ToString() }
                        };

                        if (!string.IsNullOrEmpty(project.ExcludeAssets))
                        {
                            props.Add("IncludeAssets", project.ExcludeAssets);
                        }

                        if (!string.IsNullOrEmpty(project.ExcludeAssets))
                        {
                            props.Add("ExcludeAssets", project.ExcludeAssets);
                        }

                        if (!string.IsNullOrEmpty(project.PrivateAssets))
                        {
                            props.Add("PrivateAssets", project.PrivateAssets);
                        }

                        ProjectFileUtils.AddItem(
                            xml,
                            "ProjectReference",
                            $"{project.ProjectPath}",
                            referenceFramework,
                            props,
                            new Dictionary <string, string>());
                    }
                }

                // Add tool references
                foreach (var tool in DotnetCLIToolReferences)
                {
                    var props      = new Dictionary <string, string>();
                    var attributes = new Dictionary <string, string>();

                    if (ToolingVersion15)
                    {
                        attributes.Add("Version", tool.Version.ToString());
                    }
                    else
                    {
                        props.Add("Version", tool.Version.ToString());
                    }

                    ProjectFileUtils.AddItem(
                        xml,
                        "DotNetCliToolReference",
                        $"{tool.Id}",
                        NuGetFramework.AnyFramework,
                        props,
                        attributes);
                }
            }
            else
            {
                // Add all project references directly
                foreach (var project in Frameworks.SelectMany(f => f.ProjectReferences).Distinct())
                {
                    var props = new Dictionary <string, string>
                    {
                        { "Name", project.ProjectName },
                        { "Project", project.ProjectGuid.ToString() }
                    };

                    if (!string.IsNullOrEmpty(project.ExcludeAssets))
                    {
                        props.Add("IncludeAssets", project.ExcludeAssets);
                    }

                    if (!string.IsNullOrEmpty(project.ExcludeAssets))
                    {
                        props.Add("ExcludeAssets", project.ExcludeAssets);
                    }

                    if (!string.IsNullOrEmpty(project.PrivateAssets))
                    {
                        props.Add("PrivateAssets", project.PrivateAssets);
                    }

                    ProjectFileUtils.AddItem(
                        xml,
                        "ProjectReference",
                        $"{project.ProjectPath}",
                        NuGetFramework.AnyFramework,
                        props,
                        new Dictionary <string, string>());
                }
            }

            return(xml);
        }
Esempio n. 9
0
            /// <inheritdoc />
            public override void Generate()
            {
                var gen = (VisualStudioProjectGenerator)Generator;
                var projectFileToolVersion = gen.ProjectFileToolVersion;
                var vcProjectFileContent   = new StringBuilder();

                vcProjectFileContent.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                vcProjectFileContent.AppendLine(string.Format("<Project DefaultTargets=\"Build\" ToolsVersion=\"{0}\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", projectFileToolVersion));
                vcProjectFileContent.AppendLine("  <ItemGroup Label=\"ProjectConfigurations\">");
                foreach (var configuration in Configurations)
                {
                    vcProjectFileContent.AppendLine(string.Format("    <ProjectConfiguration Include=\"{0}\">", configuration.Name));
                    vcProjectFileContent.AppendLine(string.Format("      <Configuration>{0}</Configuration>", configuration.Text));
                    vcProjectFileContent.AppendLine(string.Format("      <Platform>{0}</Platform>", configuration.ArchitectureName));
                    vcProjectFileContent.AppendLine("    </ProjectConfiguration>");
                }
                vcProjectFileContent.AppendLine("  </ItemGroup>");
                vcProjectFileContent.AppendLine("  <PropertyGroup Label=\"Globals\">");
                vcProjectFileContent.AppendLine(string.Format("    <ProjectGuid>{0}</ProjectGuid>", ProjectGuid.ToString("B").ToUpperInvariant()));
                vcProjectFileContent.AppendLine(string.Format("    <RootNamespace>{0}</RootNamespace>", Name));
                vcProjectFileContent.AppendLine(string.Format("    <MinimumVisualStudioVersion>{0}</MinimumVisualStudioVersion>", projectFileToolVersion));
                vcProjectFileContent.AppendLine(string.Format("    <AndroidAPILevel>{0}</AndroidAPILevel>", Configuration.AndroidPlatformApi));
                vcProjectFileContent.AppendLine(string.Format("    <AndroidSupportedAbis>{0}</AndroidSupportedAbis>", "arm64-v8a"));
                vcProjectFileContent.AppendLine("    <ConfigurationType>Application</ConfigurationType>");
                vcProjectFileContent.AppendLine("    <AntPackage>");
                vcProjectFileContent.AppendLine("      <AndroidAppLibName>$(RootNamespace)</AndroidAppLibName>");
                vcProjectFileContent.AppendLine("    </AntPackage>");
                vcProjectFileContent.AppendLine("  </PropertyGroup>");
                vcProjectFileContent.AppendLine("  <Import Project=\"$(AndroidTargetsPath)\\Android.Default.props\" />");
                vcProjectFileContent.AppendLine("  <Import Project=\"$(AndroidTargetsPath)\\Android.props\" />");
                vcProjectFileContent.AppendLine("  <ImportGroup Label=\"ExtensionSettings\" />");
                vcProjectFileContent.AppendLine("  <ImportGroup Label=\"Shared\" />");
                vcProjectFileContent.AppendLine("  <PropertyGroup Label=\"UserMacros\" />");
                vcProjectFileContent.AppendLine("  <PropertyGroup />");
                vcProjectFileContent.AppendLine("  <Import Project=\"$(AndroidTargetsPath)\\Android.targets\" />");
                vcProjectFileContent.AppendLine("  <ImportGroup Label=\"ExtensionTargets\" />");
                vcProjectFileContent.AppendLine("</Project>");
                Utilities.WriteFileIfChanged(Path, vcProjectFileContent.ToString());
            }
Esempio n. 10
0
        public override void SaveTo(Uri location)
        {
            var projectPath = location.LocalPath;
            var projectDir  = Path.GetDirectoryName(projectPath);

            var msBuildProject = new MsBuild.Project();

            msBuildProject.DefaultToolsVersion = "4.0";
            msBuildProject.DefaultTargets      = "Build";

            var propertyGroup = msBuildProject.AddNewPropertyGroup(false);

            propertyGroup.AddNewProperty("ProjectGuid", ProjectGuid.ToString("B").ToUpper());
            propertyGroup.AddNewProperty("Configuration", "Debug");
            propertyGroup.AddNewProperty("Platform", "x86");
            propertyGroup.AddNewProperty("OutputType", "Library");
            propertyGroup.AddNewProperty("RootNamespace", "VVVV.Nodes");
            propertyGroup.AddNewProperty("AssemblyName", AssemblyName);
            propertyGroup.AddNewProperty("TargetFrameworkVersion", "v4.0");
            propertyGroup.AddNewProperty("OutputPath", "bin\\Debug\\");
            propertyGroup.AddNewProperty("DebugSymbols", "True");
            propertyGroup.AddNewProperty("DebugType", "Full");
            propertyGroup.AddNewProperty("Optimize", "False");
            propertyGroup.AddNewProperty("CheckForOverflowUnderflow", "True");
            propertyGroup.AddNewProperty("DefineConstants", "DEBUG;TRACE");
            propertyGroup.AddNewProperty("AllowUnsafeBlocks", "True");

            //add loaded reference paths
            var expandedVVVV45Path = msBuildProject.GetEvaluatedProperty("ReferencePath");

            foreach (var refPath in ReferencePaths)
            {
                if (refPath != expandedVVVV45Path)
                {
                    if (Path.IsPathRooted(refPath))
                    {
                        propertyGroup.AddNewProperty("ReferencePath", PathUtils.MakeRelativePath(projectDir + @"\", refPath + @"\"));
                    }
                    else
                    {
                        propertyGroup.AddNewProperty("ReferencePath", refPath);
                    }
                }
            }

            msBuildProject.AddNewImport("$(MSBuildBinPath)\\Microsoft.CSharp.Targets", null);

            //add reference items
            foreach (var reference in References)
            {
                var item = msBuildProject.AddNewItem("Reference", reference.Name);
                if (!reference.IsGlobal && !InReferencePaths(reference.Name))
                {
                    var hintPath = reference.GetRelativePath();
                    item.SetMetadata("HintPath", hintPath);
                }
            }

            foreach (var document in Documents)
            {
                msBuildProject.AddNewItem(document.CanBeCompiled ? "Compile" : "None", document.GetRelativePath());
            }

            // Create the project directory if it doesn't exist yet.
            if (!Directory.Exists(projectDir))
            {
                Directory.CreateDirectory(projectDir);
            }

            msBuildProject.Save(projectPath);

            base.SaveTo(location);
        }
Esempio n. 11
0
        protected override void ProcessRecord()
        {
            try
            {
                if (Path != null)
                {
                    WriteObject((Collection == null) ? ProjectRootElement.Create(Path) : ProjectRootElement.Create(Path, Collection), false);
                }
                else if (Xml != null)
                {
                    WriteObject((Collection == null) ? ProjectRootElement.Create(ValidateXmlSourceAttribute.AsXmlReader(Xml)) : ProjectRootElement.Create(ValidateXmlSourceAttribute.AsXmlReader(Xml), Collection), false);
                }
                else
                {
                    ProjectRootElement project = (Collection == null) ? ProjectRootElement.Create() : ProjectRootElement.Create(Collection);
                    project.DefaultTargets = DefaultTargets;
                    project.AddImport("$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props").Condition = "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')";
                    ProjectPropertyGroupElement propertyGroup = project.AddPropertyGroup();
                    propertyGroup.Condition = "";
                    propertyGroup.AddProperty("Configuration", Configuration).Condition = " $(Configuration)' == '' ";
                    propertyGroup.AddProperty("Platform", Platform).Condition           = " $(Configuration)' == '' ";
                    propertyGroup.AddProperty("ProjectGuid", ProjectGuid.ToString("B").ToUpper());
                    propertyGroup.AddProperty("OutputType", OutputType);
                    propertyGroup.AddProperty("RootNamespace", RootNamespace);
                    propertyGroup.AddProperty("AssemblyName", (String.IsNullOrWhiteSpace(AssemblyName)) ? RootNamespace : AssemblyName);
                    propertyGroup.AddProperty("TargetFrameworkVersion", ToolLocationHelper.GetDotNetFrameworkVersionFolderPrefix(TargetFrameworkVersion));
                    project.AddImport("$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
                    WriteObject(project);
                    propertyGroup = project.AddPropertyGroup();
                    if (Configuration == "Debug" || Configuration == "Release")
                    {
                        propertyGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|" + Platform + "' ";
                    }
                    else
                    {
                        propertyGroup.Condition = " '$(Configuration)|$(Platform)' == '" + Configuration + "|" + Platform + "' ";
                    }
                    propertyGroup.AddProperty("DebugSymbols", "true");
                    propertyGroup.AddProperty("DebugType", "full");
                    propertyGroup.AddProperty("Optimize", "false");
                    if (Configuration == "Debug" || Configuration == "Release")
                    {
                        propertyGroup.AddProperty("OutputPath", "bin\\" + Platform);
                    }
                    else
                    {
                        propertyGroup.AddProperty("OutputPath", "bin\\Debug");
                    }
                    propertyGroup.AddProperty("DefineConstants", "DEBUG;TRACE");
                    propertyGroup.AddProperty("ErrorReport", "prompt");
                    propertyGroup.AddProperty("WarningLevel", "4");

                    propertyGroup           = project.AddPropertyGroup();
                    propertyGroup.Condition = " '$(Configuration)|$(Platform)' == 'Release|" + Platform + "' ";
                    propertyGroup.AddProperty("DebugType", "pdbonly");
                    propertyGroup.AddProperty("Optimize", "true");
                    propertyGroup.AddProperty("OutputPath", "bin\\Release");
                    propertyGroup.AddProperty("DefineConstants", "TRACE");
                    propertyGroup.AddProperty("ErrorReport", "prompt");
                    propertyGroup.AddProperty("WarningLevel", "4");

                    ProjectItemGroupElement itemGroup = project.AddItemGroup();
                    itemGroup.AddItem("Reference", "System");
                    itemGroup.AddItem("Reference", "System.Core");
                    itemGroup.AddItem("Reference", "Microsoft.CSharp");
                    itemGroup.AddItem("Reference", "System.Xml");
                    Assembly assembly = (typeof(PSObject)).Assembly;
                    itemGroup.AddItem("Reference", assembly.FullName + ", processorArchitecture=MSIL",
                                      new KeyValuePair <string, string>[]
                    {
                        new KeyValuePair <string, string>("SpecificVersion", "false"),
                        new KeyValuePair <string, string>("HintPath", assembly.Location)
                    });
                    assembly = (typeof(Microsoft.PowerShell.Commands.OutStringCommand)).Assembly;
                    itemGroup.AddItem("Reference", assembly.FullName + ", processorArchitecture=MSIL",
                                      new KeyValuePair <string, string>[]
                    {
                        new KeyValuePair <string, string>("SpecificVersion", "false"),
                        new KeyValuePair <string, string>("HintPath", assembly.Location)
                    });
                    assembly = (typeof(Microsoft.PowerShell.Commands.GetItemCommand)).Assembly;
                    itemGroup.AddItem("Reference", assembly.FullName + ", processorArchitecture=MSIL",
                                      new KeyValuePair <string, string>[]
                    {
                        new KeyValuePair <string, string>("SpecificVersion", "false"),
                        new KeyValuePair <string, string>("HintPath", assembly.Location)
                    });
                    WriteObject(project);
                }
            }
            catch (Exception exception)
            {
                WriteError(new ErrorRecord(exception, "New_MSBuildProject", ErrorCategory.OpenError, null));
            }
        }
Esempio n. 12
0
 public string GetGuidString()
 {
     return(ProjectGuid.ToString().ToUpper());
 }