小编Doo*_*ins的帖子

通过Visual Studio自动化设置项目的OutputPath属性

我正在写一个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)

非常感谢任何人的帮助.

c# msbuild envdte visual-studio-2012

10
推荐指数
2
解决办法
2万
查看次数

为什么TZCNT可以用于我的Sandy Bridge处理器?

我正在运行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)

x86 assembly x86-64

5
推荐指数
1
解决办法
999
查看次数

三元运算符,通过引用到const来延长临时对象的生命周期

在看到本地引用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任一方式操作的统一代码.

上面的例子,但是,在调用小玩意儿的拷贝构造函数argfrobnicatefalse.我设法通过更改Frobnicate(arg)为避免复制构造函数的调用static_cast<const Gizmo&>(Frobnicate(arg)).

我的问题变成:三元运算符如何与关于将本地引用到const绑定到临时的规则进行交互?我的解决方案是否合法且表现良好?

c++ copy-constructor temporary-objects c++11

4
推荐指数
1
解决办法
675
查看次数