-
Notifications
You must be signed in to change notification settings - Fork 635
Building a Package for Dynamo in Visual Studio
If you are developing assemblies to be published in a package for Dynamo, you can easily configure your project to gather all the necessary assets and put them in a package-compatible directory structure. This enables you to move quickly from building your project to testing it as a package, simulating the way that users will experience your package.
There are two methods for doing this:
- Add post-build events through the project settings dialogue, and use xcopy, python scripts, etc., to copy the necessary files.
- Use the "AfterBuild" build target in your
.csproj
file to create file and directory copy tasks. This is the method that will be covered in this article, and the preferred method for these types of operations as it does not rely on technologies for file copying which may not be available on the build machine.
The first thing you'll want to do is setup the directory structure in your repository so that there is a packages
folder at the top level. We'll be storing all the packages generated by your project in that folder. An example repository could look like this:
MyDynamoPackage
|- bin
|- extern
|- packages
| |- MyDynamoPackage
| |- bin
| | |- foo1.dll
| | |- foo2.dll
| |- dyf
| |- extra
| | |- example1.dyn
| | |- example2.dyn
| |- pkg.json
|- src
In order to add an "AfterBuild" target, you'll have to edit the .csproj
file for your project. You can place your build target at the end of the .csproj
file, before the closing </Project>
tag. An example of an AfterBuild target which gathers some files, creates some directories, and places the files in those directories looks like this:
...
<Target Name="AfterBuild">
<ItemGroup>
<Dlls Include="$(OutDir)*.dll" />
<Pdbs Include="$(OutDir)*.pdb" />
<Xmls Include="$(OutDir)*.xml" />
<Configs Include="$(OutDir)*.config" />
</ItemGroup>
<Copy SourceFiles="@(Dlls)" DestinationFolder="$(SolutionDir)..\packages\MyDynamoPackage\bin\" />
<Copy SourceFiles="@(Pdbs)" DestinationFolder="$(SolutionDir)..\packages\MyDynamoPackage\bin\" />
<Copy SourceFiles="@(Xmls)" DestinationFolder="$(SolutionDir)..\packages\MyDynamoPackage\bin\" />
<Copy SourceFiles="@(Configs)" DestinationFolder="$(SolutionDir)..\packages\MyDynamoPackage\bin\" />
<MakeDir Directories="$(SolutionDir)..\packages\MyDynamoPackage\dyf" />
<MakeDir Directories="$(SolutionDir)..\packages\MyDynamoPackage\extra" />
</Target>
...
In the <ItemGroup>
section, we define a number of variables that will be used later on to represent a set of files. For example, the Dll
variable represents all files in the ouput directory whose extension is .dll
. Later on, you can see a Copy
task which specifies that those files should be copied to the package folder.
We also use a MakeDir
task to create an extra
and a dyf
folder. Contents of the extra
folder and the dyf
folder containing things like example .dyn
files and custom nodes, which might not be affected by your build process. This MakeDir
task ensures that the folder is there, but will NOT overwrite the extra folder if it already exists. This means you can put your extra
and dyf
content directly into your packages
directory. Similarly, the pkg.json
file can live at the top level of your package folder. It won't be deleted during build.
When you build you project, you should find that the assets you specified in copy tasks have been moved to your packages directory. To test the package on Dynamo, simply copy the MyDynamoPackage
folder int your <user>\AppData\Roaming\Dynamo\0.x\packages
folder and run Dynamo.
Looking for help with using the Dynamo application? Try dynamobim.org.
- Dynamo 2.0 Language Changes Explained
- How Replication and Replication Guide work: Part 1
- How Replication and Replication Guide work: Part 2
- How Replication and Replication Guide work: Part 3