public DotNetSdkTestBase() { Assert.True(s_dotnetInstallDir != null, $"SDK not found. Use {nameof(ConditionalFactAttribute)}(typeof({nameof(DotNetSdkAvailable)})) to skip the test if the SDK is not found."); DotNetPath = Path.Combine(s_dotnetInstallDir, s_dotnetExeName); var testBinDirectory = Path.GetDirectoryName(typeof(DotNetSdkTests).Assembly.Location); var sdksDir = Path.Combine(s_dotnetSdkPath, "Sdks"); ProjectName = "test"; ProjectFileName = ProjectName + ".csproj"; Configuration = "Debug"; TargetFramework = "netstandard2.0"; ProjectDir = Temp.CreateDirectory(); ObjDir = ProjectDir.CreateDirectory("obj"); OutDir = ProjectDir.CreateDirectory("bin").CreateDirectory(Configuration).CreateDirectory(TargetFramework); Project = ProjectDir.CreateFile(ProjectFileName).WriteAllText(s_projectSource); ProjectDir.CreateFile("TestClass.cs").WriteAllText(s_classSource); // avoid accidental dependency on files outside of the project directory: ProjectDir.CreateFile("Directory.Build.props").WriteAllText("<Project/>"); ProjectDir.CreateFile("Directory.Build.targets").WriteAllText("<Project/>"); ProjectDir.CreateFile(".editorconfig").WriteAllText("root = true"); var csharpCoreTargets = Path.Combine(testBinDirectory, "Microsoft.CSharp.Core.targets"); var visualBasicCoreTargets = Path.Combine(testBinDirectory, "Microsoft.VisualBasic.Core.targets"); Assert.True(File.Exists(csharpCoreTargets)); Assert.True(File.Exists(visualBasicCoreTargets)); EnvironmentVariables = new Dictionary <string, string>() { { "CSharpCoreTargetsPath", csharpCoreTargets }, { "VisualBasicCoreTargetsPath", visualBasicCoreTargets }, { "MSBuildSDKsPath", sdksDir }, { "DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR", sdksDir } }; var restoreResult = ProcessUtilities.Run(DotNetPath, $@"msbuild ""{Project.Path}"" /t:restore /bl:{Path.Combine(ProjectDir.Path, "restore.binlog")}", additionalEnvironmentVars: EnvironmentVariables); Assert.True(restoreResult.ExitCode == 0, $"Failed with exit code {restoreResult.ExitCode}: {restoreResult.Output}"); Assert.True(File.Exists(Path.Combine(ObjDir.Path, "project.assets.json"))); Assert.True(File.Exists(Path.Combine(ObjDir.Path, ProjectFileName + ".nuget.g.props"))); Assert.True(File.Exists(Path.Combine(ObjDir.Path, ProjectFileName + ".nuget.g.targets"))); }
public void Test_Build_Project_with_Resources_with_Space_in_Path_Should_Succeed() { var spaceBufferDirectory = _root.CreateDirectory("space directory"); var testAppDir = spaceBufferDirectory.CreateDirectory("TestProjectWithResource"); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestProjectWithResource"), testAppDir); var testProject = GetProjectPath(testAppDir); var buildCommand = new BuildCommand(testProject); buildCommand.Execute().Should().Pass(); }
public void SolutionWithPunctuation() { var testDir = _tempDirectory.CreateDirectory(@"SLN;!@(goo)'^1"); var slnFile = testDir.CreateFile("Console;!@(goo)'^(Application1.sln").WriteAllText( @" Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2005 Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Cons.ole;!@(goo)'^(Application1"", ""Console;!@(goo)'^(Application1\Cons.ole;!@(goo)'^(Application1.csproj"", ""{770F2381-8C39-49E9-8C96-0538FA4349A7}"" EndProject Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Class;!@(goo)'^(Library1"", ""Class;!@(goo)'^(Library1\Class;!@(goo)'^(Library1.csproj"", ""{0B4B78CC-C752-43C2-BE9A-319D20216129}"" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {770F2381-8C39-49E9-8C96-0538FA4349A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {770F2381-8C39-49E9-8C96-0538FA4349A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {770F2381-8C39-49E9-8C96-0538FA4349A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {770F2381-8C39-49E9-8C96-0538FA4349A7}.Release|Any CPU.Build.0 = Release|Any CPU {0B4B78CC-C752-43C2-BE9A-319D20216129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0B4B78CC-C752-43C2-BE9A-319D20216129}.Debug|Any CPU.Build.0 = Debug|Any CPU {0B4B78CC-C752-43C2-BE9A-319D20216129}.Release|Any CPU.ActiveCfg = Release|Any CPU {0B4B78CC-C752-43C2-BE9A-319D20216129}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal "); var appDir = testDir.CreateDirectory(@"Console;!@(goo)'^(Application1"); var appProjFile = appDir.CreateFile(@"Cons.ole;!@(goo)'^(Application1.csproj").WriteAllText( @" <Project DefaultTargets=""Build"" ToolsVersion=""3.5"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Csc"" AssemblyFile=""" + _buildTaskDll + @""" /> <PropertyGroup> <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration> <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform> <ProductVersion>8.0.50510</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{770F2381-8C39-49E9-8C96-0538FA4349A7}</ProjectGuid> <OutputType>Exe</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>Console____goo____Application1</RootNamespace> <AssemblyName>Console%3b!%40%28goo%29%27^%28Application1</AssemblyName> </PropertyGroup> <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ""> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ""> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include=""System"" /> <Reference Include=""System.Data"" /> <Reference Include=""System.Xml"" /> </ItemGroup> <ItemGroup> <Compile Include=""Program.cs"" /> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\Class%3b!%40%28goo%29%27^%28Library1\Class%3b!%40%28goo%29%27^%28Library1.csproj""> <Project>{0B4B78CC-C752-43C2-BE9A-319D20216129}</Project> <Name>Class%3b!%40%28goo%29%27^%28Library1</Name> </ProjectReference> </ItemGroup> <Import Project=""$(MSBuildBinPath)\Microsoft.CSharp.targets"" /> </Project> "); var appProgramFile = appDir.CreateFile("Program.cs").WriteAllText( @" using System; using System.Collections.Generic; using System.Text; namespace Console____goo____Application1 { class Program { static void Main(string[] args) { Class____goo____Library1.Class1 goo = new Class____goo____Library1.Class1(); } } }"); var libraryDir = testDir.CreateDirectory(@"Class;!@(goo)'^(Library1"); var libraryProjFile = libraryDir.CreateFile("Class;!@(goo)'^(Library1.csproj").WriteAllText( @" <Project DefaultTargets=""Build"" ToolsVersion=""3.5"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Csc"" AssemblyFile=""" + _buildTaskDll + @""" /> <PropertyGroup> <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration> <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform> <ProductVersion>8.0.50510</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{0B4B78CC-C752-43C2-BE9A-319D20216129}</ProjectGuid> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>Class____goo____Library1</RootNamespace> <AssemblyName>Class%3b!%40%28goo%29%27^%28Library1</AssemblyName> </PropertyGroup> <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ""> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ""> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include=""System"" /> <Reference Include=""System.Data"" /> <Reference Include=""System.Xml"" /> </ItemGroup> <ItemGroup> <Compile Include=""Class1.cs"" /> </ItemGroup> <Import Project=""$(MSBuildBinPath)\Microsoft.CSharp.targets"" /> <!-- The old OM, which is what this solution is being built under, doesn't understand BeforeTargets, so this test was failing, because _AssignManagedMetadata was set up as a BeforeTarget for Build. Copied here so that build will return the correct information again. --> <Target Name=""BeforeBuild""> <ItemGroup> <BuiltTargetPath Include=""$(TargetPath)""> <ManagedAssembly>$(ManagedAssembly)</ManagedAssembly> </BuiltTargetPath> </ItemGroup> </Target> </Project> "); var libraryClassFile = libraryDir.CreateFile("Class1.cs").WriteAllText( @" namespace Class____goo____Library1 { public class Class1 { } } "); var result = RunCommandLineCompiler(s_msbuildExecutable, "/p:UseSharedCompilation=false", testDir.Path); Assert.Equal(0, result.ExitCode); Assert.Equal("", result.Errors); }