您尚未登录。

楼主 #1 2019-10-29 09:10:38

firstman
会员
注册时间: 2019-04-06
已发帖子: 279
积分: 279

vs工程生成脚本,一个由源文件自动生成vs2012工程的脚本,使用时放到源文件的根目录下,直接执行就可以看到效果了。

vs工程生成脚本,一个由源文件自动生成vs2012工程的脚本,使用时放到源文件的根目录下,直接执行就可以看到效果了。

由于脚本是python编写的,请先安装python2.

下载地址: https://download.csdn.net/download/ybxuwei/9447004

# vsproj.py
import uuid
import os
import os.path
import re

def write_file(filepath, str):
	f = file(filepath, "w")
	f.write(str)
	f.close()


proj_uuid = str(uuid.uuid1()).upper()
cwd = os.getcwd()
proj_name = cwd[cwd.rfind("\\")+1:]
vs_dir = "vs2012"
# sln 

sln = \
"Microsoft Visual Studio Solution File, Format Version 12.00"\
"\n# Visual Studio 2012"\
"\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$proj_name\", \"vs2012.vcxproj\", \"{$proj_uuid}\""\
"\nEndProject"\
"\nGlobal"\
"\n	GlobalSection(SolutionConfigurationPlatforms) = preSolution"\
"\n		Debug|Win32 = Debug|Win32"\
"\n		Release|Win32 = Release|Win32"\
"\n	EndGlobalSection"\
"\n	GlobalSection(ProjectConfigurationPlatforms) = postSolution"\
"\n		{$proj_uuid}.Debug|Win32.ActiveCfg = Debug|Win32"\
"\n		{$proj_uuid}.Release|Win32.ActiveCfg = Debug|Win32"\
"\n	EndGlobalSection"\
"\n	GlobalSection(SolutionProperties) = preSolution"\
"\n		HideSolutionNode = FALSE"\
"\n	EndGlobalSection"\
"\nEndGlobal\n"
sln = sln.replace("$proj_uuid", proj_uuid).replace("$proj_name", proj_name)
#print sln

# vcxproj
vcproj = \
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
"\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"\
"\n  <ItemGroup Label=\"ProjectConfigurations\">"\
"\n    <ProjectConfiguration Include=\"Debug|Win32\">"\
"\n      <Configuration>Debug</Configuration>"\
"\n      <Platform>Win32</Platform>"\
"\n    </ProjectConfiguration>"\
"\n  </ItemGroup>"\
"\n  <Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.Default.props\" />"\
"\n  <Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.props\" />"\
"\n  <ImportGroup Label=\"ExtensionSettings\">"\
"\n  </ImportGroup>  "\
"\n  <ImportGroup Label=\"PropertySheets\" Condition=\"\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'\">"\
"\n    <Import Project=\"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists(\'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props\')\" Label=\"LocalAppDataPlatform\" />"\
"\n  </ImportGroup>"\
"\n  <PropertyGroup Condition=\"\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'\" Label=\"Configuration\">"\
"\n    <ConfigurationType>Application</ConfigurationType>"\
"\n    <UseDebugLibraries>true</UseDebugLibraries>"\
"\n    <PlatformToolset>v110</PlatformToolset>"\
"\n    <CharacterSet>MultiByte</CharacterSet>"\
"\n  </PropertyGroup>"\
"\n  <PropertyGroup Label=\"Globals\">"\
"\n    <ProjectGuid>{$proj_uuid}</ProjectGuid>"\
"\n    <RootNamespace>vs2012</RootNamespace>"\
"\n    <ProjectName>$proj_name</ProjectName>"\
"\n  </PropertyGroup>"\
"\n  <Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.Default.props\" />"\
"\n  <PropertyGroup Condition=\"\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'\" Label=\"Configuration\">"\
"\n    <ConfigurationType>Application</ConfigurationType>"\
"\n    <UseDebugLibraries>true</UseDebugLibraries>"\
"\n    <PlatformToolset>v110</PlatformToolset>"\
"\n    <CharacterSet>MultiByte</CharacterSet>"\
"\n  </PropertyGroup>"\
"\n  <Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.props\" />"\
"\n  <ImportGroup Label=\"ExtensionSettings\">"\
"\n  </ImportGroup>"\
"\n  <ImportGroup Label=\"PropertySheets\" Condition=\"\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'\">"\
"\n    <Import Project=\"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists(\'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props\')\" Label=\"LocalAppDataPlatform\" />"\
"\n  </ImportGroup>"\
"\n  <PropertyGroup Label=\"UserMacros\" />"\
"\n  <PropertyGroup Condition=\"\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'\">"\
"\n    <IncludePath>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath)</IncludePath>"\
"\n  </PropertyGroup>"\
"\n  <ItemDefinitionGroup Condition=\"\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'\">"\
"\n    <ClCompile>"\
"\n      <WarningLevel>Level3</WarningLevel>"\
"\n      <Optimization>Disabled</Optimization>"\
"\n      <AdditionalIncludeDirectories>..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>"\
"\n    </ClCompile>"\
"\n    <Link>"\
"\n      <GenerateDebugInformation>true</GenerateDebugInformation>"\
"\n    </Link>"\
"\n  </ItemDefinitionGroup>"\
"\n  <ItemGroup>"\
"$item_list"\
"\n  </ItemGroup>"\
"\n  <Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.targets\" />"\
"\n  <ImportGroup Label=\"ExtensionTargets\">"\
"\n  </ImportGroup>"\
"\n</Project>"

#print vcproj

# filters

filters = \
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
"\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"\
"\n  <ItemGroup>"\
"$item_groups"\
"\n  </ItemGroup>"\
"\n</Project>"

filter_group = \
"\n    <Filter Include=\"$dir\">"\
"\n      <UniqueIdentifier>{$uuid}</UniqueIdentifier>"\
"\n    </Filter>"\

normal_group = \
"\n    <$type Include=\"$file\">"\
"\n      <Filter>$dir</Filter>"\
"\n    </$type>"\


normal_group2 = "\n    <$type Include=\"$file\" />"

#print uuid.uuid1()
groups = ""
list = ""
def gen_groups(rootdir):
	global groups
	global list
	c_groups = ""
	i_groups = ""
	t_groups = ""
	f_groups = ""
	c_list = ""
	i_list = ""
	t_list = ""
	
	for parent,dirnames,filenames in os.walk(rootdir):
		parent = re.sub(r"^\.\\*", "", parent)
		#print parent
		for file in filenames:
			if len(parent) == 0:
				path = "..\\%s"%(file);
			else:	
				path = "..\\%s\\%s"%(parent,file)
			if(re.search(r'\.cc$|\.cpp$', file)):
				c_groups += normal_group.replace("$type", "ClCompile").replace("$file", path).replace("$dir", parent)
				c_list += normal_group2.replace("$type", "ClCompile").replace("$file", path)
			if(re.search(r'\.h$', file)):
				i_groups += normal_group.replace("$type", "ClInclude").replace("$file", path).replace("$dir", parent)
				i_list += normal_group2.replace("$type", "ClInclude").replace("$file", path)
			if(re.search(r'\.mk$', file)):
				t_groups += normal_group.replace("$type", "Text").replace("$file", path).replace("$dir", parent)
				t_list += normal_group2.replace("$type", "Text").replace("$file", path)				
		for dir in dirnames:
			if len(parent) == 0:
				path = dir;
			else:	
				path = "%s\\%s"%(parent,dir)
			if dir != vs_dir:	
				f_groups += filter_group.replace("$dir",path).replace("$uuid", str(uuid.uuid1()).upper())
		groups = f_groups + i_groups + c_groups + t_groups;
		list = c_list + i_list + t_list
		
gen_groups(".")
print groups
filters = filters.replace("$item_groups", groups)
#print filters
vcproj = vcproj.replace("$proj_uuid", proj_uuid)
vcproj = vcproj.replace("$proj_name", proj_name)
vcproj = vcproj.replace("$item_list", list)
# mkdir vs_dir
if os.path.exists(vs_dir) == False:
	os.mkdir(vs_dir)
#gen files
write_file(vs_dir+"\\vs2012.vcxproj.filters",filters)
write_file(vs_dir+"\\vs2012.vcxproj",vcproj)
write_file(vs_dir+"\\vs2012.sln",sln)

离线

楼主 #2 2019-10-29 09:12:07

firstman
会员
注册时间: 2019-04-06
已发帖子: 279
积分: 279

Re: vs工程生成脚本,一个由源文件自动生成vs2012工程的脚本,使用时放到源文件的根目录下,直接执行就可以看到效果了。

能生成工程文件,在 vs2012/ 目录下。

但是不好用,不知道是不是因为我的 VS2017 的原因。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn