To an earlier question of mine, invovling VBC and NAnt with WinForms,我已经提出了一个更好的说明方式。
在vbproj文件中,您有以下内容:
<ItemGroup>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</Content>
</ItemGroup>
当从Visual Studio中运行构建(Debug Verbosity设置为Normal)时,其中一行产生的是:
Target CoreCompile:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Vbc.exe ...
其中包括vbc.exe运行所需的所有设置。但是,从Visual Studio中获取该字符串,并直接在命令行上运行它会产生:
... My Project\Settings.Designer.vb(67) : error BC30002: Type 'My.MySettings' is not defined.
Friend ReadOnly Property Settings() As Global.My.MySettings
...\My Project\Settings.Designer.vb(69) : error BC30456: 'My' is not a member of '<Default>'.
Return Global.My.MySettings.Default
如何从命令行运行上述生成器,或者是否在某处调用将生成vbc.exe正确运行命令字符串所需的正确临时文件?
答案 0 :(得分:4)
查看visual studio中的构建字符串的问题是它实际上并没有调用vbc.exe来构建visual studio。 Visual Studio中的所有构建都使用内存中的编译器而不是命令行编译器(对于C#也是如此)。
看起来像vbc.exe的命令是生成的字符串,实际上并未执行。如果要查找构建项目的正确字符串,请从visual studio命令提示符运行以下代码。
msbuild / v:diag myproject.vbproj
这将生成一个msbuild日志文件(它会很长,所以我建议管道到文件)。构建完成后,在该文件中搜索vbc.exe。它将具有构建项目所需的实际命令行。
答案 1 :(得分:0)
我今天花了一些时间研究它。我想知道如何使vbc编译器在“我的”命名空间方面正常工作,但我设法让我的NAnt脚本使用NAnt contrib(http://nantcontrib.sourceforge)。净/).
NAnt contrib允许你使用.NET msbuild进行构建,这至少允许我设置自动构建,通知等。它不能提供我想要的精细控制,但它可以实现其目的。
此任务的参考是:
http://nantcontrib.sourceforge.net/release/latest/help/tasks/msbuild.html
我的构建脚本中的相关片段:
<target name="build" depends="clean">
<msbuild project="ProjectName.vbproj" />
</target>
我在CS应用程序中使用过NAnt,但这是VB.NET应用程序的第一个。