public void ProjectWithSdkImportsIsCloneable(string projectFormatString)
        {
            _env.SetEnvironmentVariable("MSBuildSDKsPath", _testSdkRoot);

            string projectInnerContents = @"
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include=""**\*.cs"" />
    <EmbeddedResource Include=""**\*.resx"" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include=""Microsoft.NETCore.App"" Version=""1.0.1"" />
  </ItemGroup>";

            File.WriteAllText(_sdkPropsPath, "<Project />");
            File.WriteAllText(_sdkTargetsPath, "<Project />");

            // Based on the new-console-project CLI template (but not matching exactly
            // should not be a deal-breaker).
            string             content = string.Format(projectFormatString, SdkName, projectInnerContents);
            ProjectRootElement project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));

            project.DeepClone();
        }
        public void ProjectWithSdkImportsIsCloneable()
        {
            File.WriteAllText(_sdkPropsPath, "<Project />");
            File.WriteAllText(_sdkTargetsPath, "<Project />");

            using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", _testSdkRoot))
            {
                // Based on the new-console-project CLI template (but not matching exactly
                // should not be a deal-breaker).
                string content = $@"<Project Sdk=""{SdkName}"" ToolsVersion=""15.0"">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include=""**\*.cs"" />
    <EmbeddedResource Include=""**\*.resx"" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include=""Microsoft.NETCore.App"" Version=""1.0.1"" />
  </ItemGroup>

</Project>";

                ProjectRootElement project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));

                project.DeepClone();
            }
        }
예제 #3
0
 public MigrationSettings(
     string projectDirectory,
     string outputDirectory,
     ProjectRootElement msBuildProjectTemplate,
     string projectXprojFilePath = null,
     string sdkDefaultsFilePath  = null) : this(
         projectDirectory, outputDirectory, projectXprojFilePath, sdkDefaultsFilePath)
 {
     MSBuildProjectTemplate = msBuildProjectTemplate != null?msBuildProjectTemplate.DeepClone() : null;
 }
예제 #4
0
        /// <summary>
        /// Test helper for validating that DeepClone and CopyFrom work as advertised.
        /// </summary>
        private static void ValidateDeepCloneAndCopyFrom(ProjectRootElement pre)
        {
            var pre2 = pre.DeepClone();

            Assert.AreNotSame(pre2, pre);
            Assert.AreEqual(pre.RawXml, pre2.RawXml);

            var pre3 = ProjectRootElement.Create();

            pre3.AddPropertyGroup(); // this should get wiped out in the DeepCopyFrom
            pre3.DeepCopyFrom(pre);
            Assert.AreEqual(pre.RawXml, pre3.RawXml);
        }
예제 #5
0
        public MigrationSettings(
            string projectDirectory,
            string outputDirectory,
            string sdkPackageVersion,
            ProjectRootElement msBuildProjectTemplate,
            string projectXprojFilePath = null)
        {
            ProjectDirectory       = projectDirectory;
            OutputDirectory        = outputDirectory;
            SdkPackageVersion      = sdkPackageVersion;
            MSBuildProjectTemplate = msBuildProjectTemplate != null?msBuildProjectTemplate.DeepClone() : null;

            ProjectXProjFilePath = projectXprojFilePath;
        }