我正在写一个VSIX包允许用户批量修改当前加载的解决方案的项目,所有的主动配置的OutputPath属性(见令人难以置信的恼人的步骤#4 在这里).
我遇到了一个非常具体的问题:当将属性设置为包含宏"$(SolutionDir)\bin\Debug"的值时(例如,写入.csproj的值被转义如下:
<OutputPath>%24%28SolutionDir%29\bin\Debug\</OutputPath>
Run Code Online (Sandbox Code Playgroud)
而不是让MSBuild扩展宏,而是创建一个名为的实际物理文件夹$(SolutionDir).我想以某种方式绕过这种逃避.
毫无疑问,MSDN文档在该领域缺乏.
我的初始代码如下:
private void MenuItemCallback(object sender, EventArgs e)
{
SolutionWideOutputDialogWindow dialog = new SolutionWideOutputDialogWindow();
dialog.ShowModal();
if (!dialog.DialogResult.HasValue || !dialog.DialogResult.Value)
{
return;
}
string requestedOutputPath = dialog.outputPathTextBox.Text;
Solution2 solution = _dte2.Solution as Solution2;
if (solution == null)
{
return;
}
Projects projects = solution.Projects;
foreach (Project project in projects)
{
Property outputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath");
outputPath.Value = requestedOutputPath;
project.Save();
}
}
Run Code Online (Sandbox Code Playgroud)
非常感谢任何人的帮助.
我正在运行Core i7 3930k,它是Sandy Bridge微体系结构的。当执行以下代码(在MSVC19,VS2015下编译)时,结果使我感到惊讶(请参阅注释):
int wmain(int argc, wchar_t* argv[])
{
uint64_t r = 0b1110'0000'0000'0000ULL;
uint64_t tzcnt = _tzcnt_u64(r);
cout << tzcnt << endl; // prints 13
int info[4]{};
__cpuidex(info, 7, 0);
int ebx = info[1];
cout << bitset<32>(ebx) << endl; // prints 32 zeros (including the bmi1 bit)
return 0;
}
Run Code Online (Sandbox Code Playgroud)
反汇编表明该tzcnt指令确实是从内在函数发出的:
uint64_t r = 0b1110'0000'0000'0000ULL;
00007FF64B44877F 48 C7 45 08 00 E0 00 00 mov qword ptr [r],0E000h
uint64_t tzcnt = _tzcnt_u64(r);
00007FF64B448787 F3 48 0F BC …Run Code Online (Sandbox Code Playgroud) 在看到本地引用const可能会延长临时的生命之后,我遇到了有条件地将本地reference-to-const绑定到函数参数或函数调用的临时结果的需要,即:
class Gizmo
{
// Rule of Five members implemented
};
Gizmo Frobnicate(const Gizmo& arg);
void ProcessGizmo(const Gizmo& arg, bool frobnicate)
{
const Foo& local = frobnicate ? Frobnicate(arg) : arg;
// Perform some work on local
}
Run Code Online (Sandbox Code Playgroud)
一个实际的例子:boolean指定是否压缩缓冲区,并且您希望编写以local任一方式操作的统一代码.
上面的例子,但是,在调用小玩意儿的拷贝构造函数arg时frobnicate是false.我设法通过更改Frobnicate(arg)为避免复制构造函数的调用static_cast<const Gizmo&>(Frobnicate(arg)).
我的问题变成:三元运算符如何与关于将本地引用到const绑定到临时的规则进行交互?我的解决方案是否合法且表现良好?