Jason Perkins avatar Jason Perkins committed e63d3ff

Add architecture support to Visual Studio C# projects

Comments (0)

Files changed (6)

src/actions/vstudio/_vstudio.lua

 	function vstudio.projectPlatform(cfg)
 		local platform = cfg.platform
 		if platform then
-			local pltarch = vstudio.archFromPlatform(cfg.platform)
+			local pltarch = vstudio.archFromPlatform(cfg.platform) or platform
 			local cfgarch = vstudio.archFromConfig(cfg)
 			if pltarch == cfgarch then
 				platform = nil

src/actions/vstudio/vs2005_csproj.lua

 		cs2005.projectsettings(prj)
 
 		for cfg in project.eachconfig(prj) do
-			cs2005.propertygroup(cfg)
+			cs2005.propertyGroup(cfg)
 			cs2005.debugProps(cfg)
 			cs2005.outputProps(cfg)
 			cs2005.compilerProps(cfg)		
 -- tackled all the permutations yet.
 --
 
-	function cs2005.arch(prj)
-		return "AnyCPU"
+	function cs2005.arch(cfg)
+		local arch = vstudio.archFromConfig(cfg)
+		if arch == "Any CPU" then
+			arch = "AnyCPU"
+		end
+		return arch
 	end
 
 
 -- Write the PropertyGroup element for a specific configuration block.
 --
 
-	function cs2005.propertygroup(cfg)
-		_p(1,'<PropertyGroup Condition=" \'$(Configuration)|$(Platform)\' == \'%s|%s\' ">', premake.esc(cfg.buildcfg), cs2005.arch(cfg))
-		if _ACTION > "vs2008" then
-			_p(2,'<PlatformTarget>%s</PlatformTarget>', cs2005.arch(cfg))
+	function cs2005.propertyGroup(cfg)
+		local arch = cs2005.arch(cfg)
+		_x(1,'<PropertyGroup Condition=" \'$(Configuration)|$(Platform)\' == \'%s|%s\' ">', cfg.buildcfg, arch)
+		if arch ~= "AnyCPU" or _ACTION > "vs2008" then
+			_x(2,'<PlatformTarget>%s</PlatformTarget>', arch)
 		end
 	end
 
 		cs2005.projectsettings_old(prj)
 
 		for cfg in premake.eachconfig(prj) do
-			cs2005.propertygroup(cfg)
+			cs2005.propertyGroup(cfg)
 
 			if cfg.flags.Symbols then
 				_p('    <DebugSymbols>true</DebugSymbols>')

tests/actions/vstudio/cs2005/propertygroup.lua

---
--- tests/actions/vstudio/cs2005/propertygroup.lua
--- Validate configuration <PropertyGroup/> elements in Visual Studio 2005+ .csproj
--- Copyright (c) 2009-2011 Jason Perkins and the Premake project
---
-
-	T.vstudio_cs2005_propertygroup = { }
-	local suite = T.vstudio_cs2005_propertygroup
-	local cs2005 = premake.vstudio.cs2005
-	local project = premake5.project
-
---
--- Setup 
---
-
-	local sln, prj, cfg
-	
-	function suite.setup()
-		sln, prj = test.createsolution()
-		language "C#"
-	end
-	
-	local function prepare()
-		cfg = project.getconfig(prj, "Debug")
-		cs2005.propertygroup(cfg)
-	end
-
-
---
--- Version Tests
---
-
-	function suite.OnVs2005()
-		_ACTION = "vs2005"
-		prepare()
-		test.capture [[
-	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-		]]
-	end
-
-
-	function suite.OnVs2008()
-		_ACTION = "vs2008"
-		prepare()
-		test.capture [[
-	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-		]]
-	end
-
-
-	function suite.OnVs2010()
-		_ACTION = "vs2010"
-		prepare()
-		test.capture [[
-	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-		<PlatformTarget>AnyCPU</PlatformTarget>
-		]]
-	end

tests/actions/vstudio/cs2005/test_platform_groups.lua

+--
+-- tests/actions/vstudio/cs2005/test_platform_groups.lua
+-- Check creation of per-platform property groups in VS2005+ C# projects.
+-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
+--
+
+	T.vstudio_cs2005_platform_groups = {}
+	local suite = T.vstudio_cs2005_platform_groups
+	local cs2005 = premake.vstudio.cs2005
+
+--
+-- Setup 
+--
+
+	local sln, prj, cfg
+	
+	function suite.setup()
+		_ACTION = "vs2008"
+	end
+	
+	local function prepare(platform)
+		sln = solution ("MySolution")
+		configurations ("Debug")
+		platforms (platform)
+		prj = project ("MyProject")
+		language "C#"
+		cfg = premake5.project.getconfig(prj, "Debug", platform)
+		cs2005.propertyGroup(cfg)
+	end
+
+
+--
+-- Check defaults.
+--
+
+	function suite.vs2008()
+		_ACTION = "vs2008"
+		prepare()
+		test.capture [[
+	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+		]]
+	end
+
+
+	function suite.vs2010()
+		_ACTION = "vs2010"
+		prepare()
+		test.capture [[
+	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+		<PlatformTarget>AnyCPU</PlatformTarget>
+		]]
+	end
+
+
+--
+-- Check handling of specific architectures.
+--
+
+	function suite.vs2008_onAnyCpu()
+		_ACTION = "vs2008"
+		prepare("Any CPU")
+		test.capture [[
+	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+		]]
+	end
+
+
+	function suite.vs2010_onAnyCpu()
+		_ACTION = "vs2010"
+		prepare("Any CPU")
+		test.capture [[
+	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+		<PlatformTarget>AnyCPU</PlatformTarget>
+		]]
+	end
+
+	function suite.onX32()
+		prepare("x32")
+		test.capture [[
+	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+		<PlatformTarget>x86</PlatformTarget>
+		]]
+	end
+
+
+	function suite.onX64()
+		prepare("x64")
+		test.capture [[
+	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+		<PlatformTarget>x64</PlatformTarget>
+		]]
+	end

tests/actions/vstudio/sln2005/test_platforms.lua

 	EndGlobalSection
 		]]
 	end
+
+
+--
+-- Check the handling of the "Any CPU" .NET architecture.
+--
+
+	function suite.onSingleCpp_withAnyCpuPlatform()
+		platforms { "Any CPU" }
+		project "MyProject"
+		prepare()
+		test.capture [[
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug Any CPU|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug Any CPU|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release Any CPU|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release Any CPU|Win32
+	EndGlobalSection
+		]]
+	end
+
+	function suite.onSingleCs_withAnyCpuPlatform()
+		platforms { "Any CPU" }
+		project "MyProject"
+		language "C#"
+		prepare()
+		test.capture [[
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+		]]
+	end
+
+	function suite.onMixedLanguage_withAnyCpuPlatform()
+		platforms { "Any CPU" }
+		project "MyProject1"
+		language "C#"
+		uuid "52AD9329-0D74-4F66-A213-E649D8CCD737"
+		
+		project "MyProject2"
+		prepare()
+		test.capture [[
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|Any CPU.Build.0 = Release|Any CPU
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug Any CPU|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug Any CPU|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release Any CPU|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release Any CPU|Win32
+	EndGlobalSection
+		]]
+	end

tests/premake4.lua

 	dofile("actions/vstudio/cs2005/test_files.lua")
 	dofile("actions/vstudio/cs2005/test_output_props.lua")
 	dofile("actions/vstudio/cs2005/projectelement.lua")
+	dofile("actions/vstudio/cs2005/test_platform_groups.lua")
 	dofile("actions/vstudio/cs2005/test_project_refs.lua")
 	dofile("actions/vstudio/cs2005/projectsettings.lua")
-	dofile("actions/vstudio/cs2005/propertygroup.lua")
 
 	-- Visual Studio 2005-2010 solutions
 	dofile("actions/vstudio/sln2005/test_dependencies.lua")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.