添加项目文件。

This commit is contained in:
GG Z
2026-02-23 11:05:30 +08:00
commit 1588dc09d1
48 changed files with 4687 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
#region
using System;
using System.IO;
using Autodesk.RevitAddIns;
#endregion
namespace DimensionTools.AddInDeployer
{
public class AddInManager
{
private readonly string vendorDescription = "深圳市地铁集团有限公司";
private readonly string vendorid = "SZMC";
internal AddInManager(string revitVersion, string addinname)
{
Manifest = new RevitAddInManifest();
ManifestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"Autodesk\\ApplicationPlugins\\DimensionTools.bundle\\Contents", revitVersion, addinname);
//ManifestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Autodesk\\Revit\\Addins", revitVersion, addinname);
}
private RevitAddInManifest Manifest { get; }
private string ManifestPath { get; }
internal void CreateApplication(string name, string assemblyPath, string fullClassName)
{
RevitAddInApplication item =
new RevitAddInApplication(name, assemblyPath, Guid.NewGuid(), fullClassName, vendorid)
{
VendorDescription = vendorDescription
};
Manifest.AddInApplications.Add(item);
}
internal void CreateCommand(string assemblyPath, string fullClassName)
{
RevitAddInCommand item = new RevitAddInCommand(assemblyPath, Guid.NewGuid(), fullClassName, vendorid)
{
VendorDescription = vendorDescription
};
Manifest.AddInCommands.Add(item);
}
internal void Install()
{
DirectoryInfo directory = new FileInfo(ManifestPath).Directory;
if (directory == null)
{
return;
}
if (!directory.Exists)
{
Directory.CreateDirectory(directory.FullName);
}
Manifest.SaveAs(ManifestPath);
}
internal void Uninstall()
{
if (File.Exists(ManifestPath))
{
File.Delete(ManifestPath);
}
}
}
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>
</startup>
<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->
</configuration>

View File

@@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace DimensionTools.AddInDeployer
{
public class CustomActions
{
public const string dllName = "DimensionTools.dll";
public const string addinName = "DimensionTools.addin";
[CustomAction]
public static ActionResult Uninstaller(Session session)
{
session.Log("Begin Uninstaller");
var commonAppDataFolder = session["CommonAppDataFolder"];
var addinFilePath = $"{commonAppDataFolder}\\Autodesk\\DimensionTools.bundle";
Directory.Delete(addinFilePath,true);
return ActionResult.Success;
}
[CustomAction]
public static ActionResult Installer(Session session)
{
session.Log("Begin Installer");
var manufacturer = session["Manufacturer"];
var productName = session["ProductName"];
var appdir = session["APPDIR"]; //安装路径,根据用户选择
var sourceDir = session["SourceDir"]; //安装包解压路径
var programFiles64Folder = session["ProgramFiles64Folder"]; //64位安装路径C:\ProgramFiles
var commonAppDataFolder = session["CommonAppDataFolder"]; //C:\ProgramData
var addinFilePath = $"{commonAppDataFolder}\\Autodesk\\DimensionTools.bundle\\Contents";
//List<RevitProduct> revitProductsInstalled = RevitProductUtility.GetAllInstalledRevitProducts();
//foreach (var product in revitProductsInstalled)
//{
//}
List<FileInfo> dlls = new List<FileInfo>();
DirectoryInfo dir = Directory.CreateDirectory(appdir);
StringBuilder sb = new StringBuilder();
foreach (var fileInfo in dir.GetFiles("*", SearchOption.AllDirectories))
{
if (fileInfo.Name == dllName)
{
dlls.Add(fileInfo);
}
}
foreach (var dllPath in dlls)
{
var versionNum = dllPath.Directory.Name;
AddInManager manager = new AddInManager(versionNum, addinName);
manager.CreateApplication("标注工具", dllPath.FullName, "DimensionTools.UiRibbon");
manager.Uninstall();
manager.Install();
}
return ActionResult.Success;
}
}
}

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1E6F7706-97B3-4929-8FF9-79DF5485801B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DimensionTools.AddInDeployer</RootNamespace>
<AssemblyName>DimensionTools.AddInDeployer</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="RevitAddInUtility">
<HintPath>C:\Program Files\Autodesk\Revit 2020\RevitAddInUtility.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.Deployment.WindowsInstaller">
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Serialization" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddInManager.cs" />
<Compile Include="CustomAction.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Content Include="CustomAction.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(WixCATargetsPath)" Condition=" '$(WixCATargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.CA.targets" Condition=" '$(WixCATargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.CA.targets') " />
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixCATargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
</Target>
</Project>

View File

@@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Szmedi.AddinDeployer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Administrator")]
[assembly: AssemblyProduct("Szmedi.AddinDeployer")]
[assembly: AssemblyCopyright("Copyright © Administrator 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1e6f7706-97b3-4929-8ff9-79df5485801b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]