我正在尝试将现有的命令行工具转换为 msbuild 自定义任务。该工具使用 System.Console 类记录消息和错误。
我已将一个继承自 Microsoft.Build.Utilities.Task 的类添加到该工具的程序集中,并调用该工具的主函数,并且自定义工具工作正常 - 但没有显示消息/错误(在 Visual Studio 输出窗口上)。
我想避免更改原始工具的代码(否则我可以将每个“Console.Error.WriteLine”更改为“Log.LogError”)。我想在调用工具的 main 函数之前通过调用 Console.SetOut 和 SetError 来更改控制台的 stdout 和 stderr 流。为此,我需要实现一个继承自 TextWriter 的类。
所以我的问题是:
谢谢。
我已经为我的C++ Visual Studio项目(vcxproj)添加了一个新的构建目标.
该目标在构建项目时运行自定义工具.该工具根据我指定的ContentType和ItemType处理解决方案上的特定文件.这适用于"Build"和"Clean"等项目操作.
现在我想支持一个等同于"编译"的动作,即右键单击解决方案资源管理器中的文件,然后选择使用我的自定义工具处理这个特定文件("编译"运行"CL"代表"C /" C++代码"文件类型".
我知道我可以添加一个Visual Studio宏来执行此操作.这对我来说不是一个好的解决方案,因为它很难为许多用户部署.更好的解决方案是自定义vcxproj(或由其导入的文件).
我想知道是否可以通过msbuild目标脚本或PropertyPageSchema在菜单中添加类似"编译"的操作(或者更改"C/C++代码"以外的文件类型的"编译"行为).
更新:我已经开始在MSDN论坛上进行讨论了.从微软主持人那里得到了一些帮助清理一些东西的答案,但问题仍然没有解决.
AvailableItemName
似乎在VS2015上解决了这个问题.例如,我有一个自定义目标来处理Excel文件.
在目标文件上:
<ItemGroup>
<PropertyPageSchema Include="$(SolutionDir)\ExcelOptions.xml" />
</ItemGroup>
<ItemGroup>
<AvailableItemName Include="Excel">
<Targets>ProcessExcel</Targets>
</AvailableItemName>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
在选项文件上:
<FileExtension Name=".xls" ContentType="Excel"/>
<ContentType Name="Excel" DisplayName="Excel File" ItemType="Excel"/>
<ItemType Name="Excel" DisplayName="Excel File"/>
Run Code Online (Sandbox Code Playgroud)
现在,在选择excel文件后,可以在解决方案资源管理器上下文菜单中访问编译,并且CTRL-F7也适用(对于可在VS上编辑的文件,而不是excel文件)
我想知道WPF实际显示了多少行DataGrid
.
我尝试循环DataGridRow
并检查IsVisible
,但似乎行报告,IsVisible = true
即使它们不在DataGrid
视口中.
如何正确计算可见行数?
mspdbsrv.exe是Microsoft内部用于更新PDB文件的实用程序.编译器通过RPC向mspdbsrv发送符号更新,mspdbsrv依次更新PDB文件.
我试图了解这些更新的样子.不幸的是,微软没有发布IDL所以我不知道RPC函数原型,但是看看这些更新,因为原始数据足够有趣.
在这种情况下,mspdbsrv.exe默认端点是\RPC Control\mspdb_10.00.30319.01_rtl_32_00000000000733A0
.但是mspdbsrv有一个命令行参数-endpoint
,可以将其端点设置为不同的端点.但是,编译器可能始终连接到默认端点.
我想我可以创建一种"代理服务器"来监听mspdbsrv默认端点,运行带有不同端点的mspdbsrv.exe,并在记录时透明地将RPC传递给mspdbsrv.由于代理公开mspdbsrv端点,编译器将不知道它已连接到代理.
这有意义吗?如何在没有IDL的情况下编写这样的代理RPC服务器?
如果有人知道有关这些PDB更新的一些细节,也许有一条捷径?
我发现了00000000000733A0
mspdbsrv端口名称的后缀是什么......(mspdb_10.00.30319.01_rtl_32_00000000000733A0
).
这是当前用户的安全访问令牌!以下是如何获取它的片段:
HANDLE hToken;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken) != 0)
{
TOKEN_STATISTICS tsStats;
DWORD dwOutSize;
if (GetTokenInformation(hToken, TokenStatistics, &tsStats, sizeof(tsStats), &dwOutSize))
{
printf(TEXT("%08x%08x\n"), (UINT)tsStats.AuthenticationId.HighPart, (UINT)tsStats.AuthenticationId.LowPart);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在运行带有一些扩展的Visual Studio 2015.
我正在尝试调试以下错误:
记录错误ActivityLog.xml
:
440 ERROR A MEF Component threw an exception at runtime: System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'.
at Microsoft.VisualStudio.Composition.Reflection.ResolverExtensions.Resolve(ConstructorRef constructorRef)
at Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimePart.get_ImportingConstructor()
at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue()
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create()
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState)
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState)
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose()
at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0()
Source: Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost
Time: 2016/09/12 07:16:43.932
441 ERROR System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'.
at Microsoft.VisualStudio.Composition.Reflection.ResolverExtensions.Resolve(ConstructorRef constructorRef)
at Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimePart.get_ImportingConstructor()
at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue()
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create()
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState)
at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) …
Run Code Online (Sandbox Code Playgroud) debugging visual-studio visual-studio-extensions visual-studio-2015
我正在使用C++(Visual Studio 2015)调试大型应用程序上的"访问冲突"异常.该应用程序是由几个库构建的,其中一个(SystemC)会出现问题,尽管我怀疑问题的根源在其他地方.
m_update_phase = true;
m_prim_channel_registry->perform_update();
m_update_phase = false;
Run Code Online (Sandbox Code Playgroud)
inline
void
sc_prim_channel_registry::perform_update()
{
for( int i = m_update_last; i >= 0; -- i ) {
m_update_array[i]->perform_update();
}
m_update_last = -1;
}
Run Code Online (Sandbox Code Playgroud)
(这些是从摘录systemc\kernel\sc_simcontext.cpp
和systemc\communication\sc_prim_channel.h
,所述的部分SystemC的库)
通过上面的代码多次迭代后发生错误.调用m_prim_channel_registry->perform_update()
抛出0xC0000005: Access violation writing location 0x0F4CD9E9.
异常.
只有在Release配置中构建应用程序时才会发生这种情况
看看汇编代码,我看到函数sc_prim_channel_registry::perform_update()
是内联的,内部函数调用m_update_array[i]->perform_update()
似乎破坏了调用函数的堆栈框架.
当m_update_last = -1;
被执行时,与m_update_last不再指向有效的存储位置,并抛出异常.
(m_update_last
是类的一个简单的天然成员sc_prim_channel_registry
具有类型int
)
m_update_phase = true;
m_prim_channel_registry->perform_update();
1034D99E mov eax,dword ptr [esi+10h]
1034D9A1 …
Run Code Online (Sandbox Code Playgroud) 我有宏执行除法并检查对齐.
#define BYTES_TO_WORDS(x) ((CHECK_ALIGNMENT(x,2)) * ((x) / 2))
Run Code Online (Sandbox Code Playgroud)
我想实现CHECK_ALIGNMENT
一个总是返回1的宏,并且如果x
不除以2 则触发错误.
宏BYTES_TO_WORDS
从不同的上下文调用,有时x
用作编译时常量整数表达式,有时x
用作整数表达式这是在运行时解决的.
是否可以实现CHECK_ALIGNMENT
,static_assert
当使用常量表达式调用宏时,它将执行,并且当表达式不是编译时常量时,会检查一些运行时错误?
我可以更改宏定义,但不能更改宏的调用和使用方式.
这是一个可能的解决方案(并不总是有效):
#define CHECK_ALIGNMENT(x,alignedTo) (1/(((alignedTo)-((x)%(alignedTo)))/(alignedTo)))
Run Code Online (Sandbox Code Playgroud)
在此实现中,我们应该在运行时或编译时获得Division By Zero错误,具体取决于输入.
但是,由于编译器错误,这并不总是有效.此外,错误消息不是很好.
一个更好的解决方案是确定参数是否是编译时常量,并static_assert
在这种情况下使用,编译时错误消息.如果参数不表示编译时常量,则检查运行时的对齐方式.
这可能吗?
我需要这个在Visual Studio 2015上工作.
关于为什么我在C++问题中使用宏,评论中有一些讨论.
所述BYTES_TO_WORDS
宏是其中通过各种工具包括一个头文件,C++编译器是其中之一.
其他工具使用此宏并评估算术表达式((x) / 2)
,但在这些工具上我定义CHECK_ALIGNMENT
为1,因为它们不能处理constexpr
,模板甚至函数调用.
当用C++编译器编译这个头时,我想定义CHECK_ALIGNMENT
一些其他东西,static_assert
在需要时会触发或运行时错误.
定义CHECK_ALIGNMENT
可以是任何C++ 11代码(或VS2015支持的C++ 14),可以使用模板,constexpr或诸如此类的东西.
~/.vim/ftplugin/verilog.vim
与我的命令一起添加(匹配规则):set filetype?
退货 filetype=verilog
:filetype
退货 filetype detection=ON plugin=ON indent=OFF
此时,好像没有加载 verilog.vim (matchit不匹配)。
仅在运行时:source ~/.vim/ftplugin/verilog.vim
-我的命令已加载(并且matchit正确匹配)
我试图了解为什么undefined reference
在链接过程中出现错误:
/home/amirgon/projects/esp8266/esp-open-sdk/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -L/home/amirgon/projects/esp8266/esp-open-sdk/sdk/lib -T/home/amirgon/projects/esp8266/esp-open-sdk/sdk/ld/eagle.app.v6.cpp.ld -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lmain build/app_app.a -Wl,--end-group -o build/app.out
build/app_app.a(routines.o):(.text+0x4): undefined reference to `pvPortMalloc(unsigned int, char const*, int)'
Run Code Online (Sandbox Code Playgroud)
gcc 抱怨它找不到函数pvPortMalloc
。
但是,我可以确认此功能存在于libmain.a
!
在上面的命令行中,libmain 被引用-lmain
并且库路径设置为-L/home/amirgon/projects/esp8266/esp-open-sdk/sdk/lib
. 当我从libmain.a
该路径转储符号时,我可以找到pvPortMalloc
标记为T
,这意味着该符号位于文本(代码)部分:
/home/amirgon/projects/esp8266/esp-open-sdk/xtensa-lx106-elf/bin/xtensa-lx106-elf-nm -g /home/amirgon/projects/esp8266/esp-open-sdk/sdk/lib/libmain.a | grep pvPortMalloc
U pvPortMalloc
0000014c T pvPortMalloc
U pvPortMalloc
Run Code Online (Sandbox Code Playgroud)
那么,我错过了什么吗?尽管函数存在于 libmain.a 中,但 gcc 找不到该函数的原因可能是什么?
如何进一步调试此错误?
我想在我的目标中使用"MSBuild"任务,以便构建另一个项目,同时将一些项目(及其元数据)从当前项目传递到要构建的项目.
虽然可以使用Properties属性或AdditionalProperties元数据传递属性,但我找不到传递Items的方法.
一种可能的解决方案是将项目写入文件并将文件名作为属性传递,但这只会传递项目,而不传递其元数据.
任何的想法?
谢谢.
微软Windows提供了多种功能来查询当前的代码页:
GetACP
,GetConsoleOutputCP
,GetConsoleCP
.
它们返回不同的值.例如,我的机器上,GetACP
返回1252,而GetConsoleOutputCP
与GetConsoleCP
返回437.
(我们也可以chcp
在命令行上运行并获得437)
此问题的背景是来自Visual Studio C++的错误消息:
error C2855: command-line option '/source-charset' inconsistent with precompiled header
error C2855: command-line option '/execution-charset' inconsistent with precompiled header
Run Code Online (Sandbox Code Playgroud)
当使用与使用它们的CPP文件(由于某种原因)不同的默认代码页构建预编译头文件时,会发生这些错误.
来自MSDN文档:
如果未找到字节顺序标记,则假定使用当前用户代码页对源文件进行编码,除非您使用/ source-charset选项指定字符集名称或代码页.
所以我试图找出他们引用的代码页,返回的代码页GetACP
或其他代码页......
windows codepages visual-studio windows-console visual-studio-2015
我正在根据项目A创建项目B,并希望将所有A的元数据复制到B(并添加一些额外的元数据).
<ItemGroup>
<B Include="@A">
<M1>%(A.M1)</M1>
<M2>%(A.M2)</M2>
<M3>%(A.M3)</M3>
...
<M100>%(A.M100)</M100>
... Additional metadata specific to B ...
</B>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
而不是将每个元数据M1-M100从A单独复制到B,是否可以告诉msbuild将所有元数据从A复制到B?
这样的"批量元数据副本"能否受到限制?
就像是:
<ItemGroup>
<B Include="@A">
... Additional metadata specific to B ...
</B>
</ItemGroup>
<CopyMetadata From="@A" To="@B" Condition="... Check something ..."/>
Run Code Online (Sandbox Code Playgroud)
谢谢.