Visual studio Visual Studio代码生成,基于项目的内容

Visual studio Visual Studio代码生成,基于项目的内容,visual-studio,code-generation,extensibility,visual-studio-express,Visual Studio,Code Generation,Extensibility,Visual Studio Express,我感兴趣的是根据.csproj中的某些文件生成一些代码。我可以使用哪些扩展性方法生成与项目一起编译的.cs文件 警告:我立即想到使用T4模板来完成任务。但是,此解决方案必须在Visual Studio C#Express上受支持。我认为express版本不支持C#express上的T4模板。答案很简单:无 C#Express不支持扩展。人们以前试过,但现在已经很难看了。律师,混乱,一切。著名的例子是 如果不介意在命令行中生成,可以使用msbuild自定义任务或预生成/后生成命令 在VS2005/

我感兴趣的是根据.csproj中的某些文件生成一些代码。我可以使用哪些扩展性方法生成与项目一起编译的.cs文件

警告:我立即想到使用T4模板来完成任务。但是,此解决方案必须在Visual Studio C#Express上受支持。我认为express版本不支持C#express上的T4模板。答案很简单:无

C#Express不支持扩展。人们以前试过,但现在已经很难看了。律师,混乱,一切。著名的例子是

如果不介意在命令行中生成,可以使用msbuild自定义任务或预生成/后生成命令

在VS2005/VS2008(“适当的”)中,“定制工具”是一种方法;这涉及到编写一个
,并开放供检查

T4是未来的另一种选择。它不适合我的需要,但可能适合你的需要


作为对构建事件的快速检查,我(在express项目中)添加了以下预构建和后构建事件(项目属性->构建事件):

分别;点击build,现在输出为:

------ Build started: Project: ConsoleApplication10, Configuration: Release Any CPU ------
echo D:\SomePath\ConsoleApplication10.exe
D:\SomePath\ConsoleApplication10.exe
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe+ /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Design.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\ConsoleApplication10.exe /target:exe Form1.cs Form1.Designer.cs Form2.cs Form2.Designer.cs Program.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
ConsoleApplication10 -> D:\SomePath\ConsoleApplication10.exe
echo D:\SomePath
D:\SomePath
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

因此,它似乎工作正常(即两个事件都已执行)。不优雅,但可行。宏应该允许您(使用一些扑克)访问项目项,例如
$(ProjectPath)SomeFile.xml

您可以打开csproj文件(它只是一个msbuild脚本)并添加自定义目标

有两个默认目标提供给您,您可以为了这样的目的覆盖它们,构建前和构建后(可能更多,但我不确定其他目标)


您还可以在新的msbuild任务中包含自定义dll,但如果您使用的是VS2005,则在打开项目时会生成安全警告,除非您将dll添加到msbuild的SafeImports列表(HKLM\Software\Microsoft\Visual Studio\9.0\msbuild\SafeImports)8.0中。

C#express是否支持构建前/后步骤?我刚刚检查过,而且似乎是,;属性->生成事件>预生成/后生成。当然,然后您必须通过外部批处理/执行来完成所有操作感谢echo。可能会有用-要记住。
echo $(SolutionDir)
------ Build started: Project: ConsoleApplication10, Configuration: Release Any CPU ------
echo D:\SomePath\ConsoleApplication10.exe
D:\SomePath\ConsoleApplication10.exe
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe+ /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Design.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\ConsoleApplication10.exe /target:exe Form1.cs Form1.Designer.cs Form2.cs Form2.Designer.cs Program.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
ConsoleApplication10 -> D:\SomePath\ConsoleApplication10.exe
echo D:\SomePath
D:\SomePath
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========