Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio Visual Studio 2008:如果dll文件正在使用,如何更改其名称?_Visual Studio - Fatal编程技术网

Visual studio Visual Studio 2008:如果dll文件正在使用,如何更改其名称?

Visual studio Visual Studio 2008:如果dll文件正在使用,如何更改其名称?,visual-studio,Visual Studio,我有这个项目MyProject 我构建了解决方案,得到了MyProject.dll文件 我将文件加载到某个程序中 我在我的解决方案中做了一些更改,然后点击了build按钮。我收到这个错误: 无法将文件“.dll”复制到“bin\Debug\.dll”。进程无法访问文件“bin\Debug\.dll”,因为另一进程正在使用该文件。 在这种情况下,如果我的.dll文件被其他程序使用,Visual Studio是否有可能生成MyProject1(2,3...dll?您不能直接执行此操作,但可以手动执行

我有这个项目MyProject

  • 我构建了解决方案,得到了MyProject.dll文件

  • 我将文件加载到某个程序中

  • 我在我的解决方案中做了一些更改,然后点击了build按钮。我收到这个错误:

  • 无法将文件“.dll”复制到“bin\Debug\.dll”。进程无法访问文件“bin\Debug\.dll”,因为另一进程正在使用该文件。


    在这种情况下,如果我的.dll文件被其他程序使用,Visual Studio是否有可能生成MyProject1(2,3...dll?

    您不能直接执行此操作,但可以手动执行。您可以将其设置为宏(更容易更改项目设置)或外部程序(需要将vcproj修改为文本或xml);伪代码倾向于外部C++实现:

    bool CanWriteDll( dll )
    {
      return FileOutputStream( dll ).is_open();
    }
    
    void BuildProject( proj )
    {
      LaunchProcess( "devenv /Build " + proj ); //or "msbuild ..." if you will
    }
    
    string FindUniqueName( dll )
    {
      string name = Path( dll ).NameWithoutExtension();
      string ext = Path( dll ).Extension();
      string newname;
      int i = 1;
      for( ; ; )
      {
        newname = name + ToString( i++ ) + ext;
        if( !FileExists( newname ) )
          return newname;
      }
    }
    
    void ModifyTargetName( proj, newName )
    {
       Xml xml = OpenXmlFile( proj );
       XmlNode node = xml.FindNode( "Tool.VCLinkerTool.OutputFile" );
       node.SetValue( "$(OutDir)\" + newName );
       xml.WriteFile();
    } 
    
      //main code
    if( !CanWriteDll( dll ) )
      ModifyTargetName( proj, FindUniqueName( dll ) );
    BuildProject( project );
    

    这就产生了一个问题,您必须使用dll重新启动应用程序,并告诉它立即使用MyProject1.dll。因此,如果您必须关闭应用程序,那么您最好先关闭它,然后构建dll,然后再次打开它。换句话说,弗雷德里克和查克的评论很贴切:你可能一开始就不应该这么做

    为什么要让一个程序从构建输出文件夹加载dll?我不知道,我也不知道为什么要加载。如果您的dll正在被其他东西使用,它应该位于项目输出文件夹之外的其他位置。