我正在创建一个revit插件,我想让它在关机时使用批处理文件自动拉取.dll and.addin文件的副本。代码和批处理文件例程本身工作正常,但是当我让它们一起运行时,我得到了一个复制.dll文件的共享冲突。谁能告诉我怎样才能绕过共享违规?其目的是将这两个文件展开到所有用户,并在他们关闭Revit时将文件更新复制到他们的计算机。
public Result OnShutdown(UIControlledApplication application)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "S:\\Revit 2015\\Addins\\Revit Tabs\\2015_RevitTab.bat";
proc.StartInfo.WorkingDirectory = "S:\\Revit 2015\\Addins\\Revit Tabs\\";
proc.Start();
return Result.Succeeded;
}下面是复制语法
xcopy "S:\Revit 2015\Addins\Revit Tabs\Revit Tabs.addin" "C:\ProgramData\Autodesk\Revit\Addins\2015" /y
xcopy "S:\Revit 2015\Addins\Revit Tabs\Revit Tabs\bin\Debug\Revit Tabs.dll" "C:\ProgramData\Autodesk\Revit\Addins\2015" /y 发布于 2016-02-01 14:30:39
可以添加对您自己的独立实用程序exe的调用,以监视当前Revit进程是否仍处于活动状态,然后在Revit确实消失后执行附加模块DLL复制进程。
发布于 2016-02-04 21:15:12
我想要同样的自动更新过程,在经过一些试验和错误之后,我找到了一些适合我的代码。希望你能使用它或改进它。
我有ribbon.addin,ribbon.dll (“功能区”)和commands.dll (“命令”)文件。所有文件都将作为展开的一部分安装到"%appdata%\Autodesk\Revit\Addins\2016“文件夹("Local")中。由于写保护问题,请务必将这些文件安装在"%appdata%“文件夹中,而不是安装在”%Programdata%\Autodesk\Revit\\2016“文件夹中!
Ribbon插件仅用于检查哪个版本的命令当前位于本地文件夹中,以及该版本是否来自于我在共享网络文件夹(“共享”)中的命令文件。由于安全原因,我无法读取本地动态链接库或共享动态链接库的AssemblyVersion。为了解决这个问题,我在本地文件夹中有一个TXT文件,它的第一行是AssemblyVersion,在共享文件夹中,我还有另一个TXT文件(实际上我有命令插件的“关于”信息),它的第一行是共享命令AssemblyVersion。
所以我的Ribbon OnStartup(UIControlledApplication a)代码使用System.IO.StreamReader检查TXT文件。如果本地文件已过期,它将使用此c#更新本地TXT和DLL文件
try
{
string AddinsDir = a.ControlledApplication.CurrentUserAddinsLocation + @"\";
string tempDir = System.IO.Path.GetTempPath();
StreamWriter myStream = new StreamWriter(tempDir + "Commands.txt", false, System.Text.Encoding.Default);
myStream.WriteLine(AssemblyVersion);
//AssemblyVersion is the first line of the Shared Commands TXT file we read
myStream.Close();
File.Copy(tempDir + "Commands.txt", AddinsDir + "Commands.txt", true);
File.Delete(tempDir + "Commands.txt");
File.Delete(AddinsDir + "Commands.dll");
File.Copy(SharedPath + "Commands.dll", AddinsDir + "Commands.dll", true);
//SharedPath is the Shared folder
}
catch (Exception e)
{
TaskDialog.Show("Error Loading Ribbon", "There was an error loading the Ribbon. Please contact the BIM Manager for assistance.\n\n" + e.Message);
return Result.Failed;
}如果此时代码仍在运行,则文件是最新的,是时候加载它了:
Assembly Commands = Assembly.LoadFrom(AddinsDir + "Commands.dll");
Type type = Commands.GetType("Commands.App");
//Commands.App is my class where my Ribbon is created and Events are registered
object instanceOfCommands = Activator.CreateInstance(type, new object[] { a });
return Result.Succeeded;我对Revit 2017展开的计划是在Ribbon.dll中创建自定义功能区,这样我就可以在那里有我的“关于”按钮,并且可以随时访问。然后,我将在"About“对话框中添加一个按钮,该按钮将手动更新Local Commands DLL。
我希望这能有所帮助!!
https://stackoverflow.com/questions/35087156
复制相似问题