乙ᗰᗩᑎ350᙭
乙ᗰᗩᑎ350᙭
CC#
Created by 乙ᗰᗩᑎ350᙭ on 4/22/2025 in #help
✅ [SOLVED] MSBuild Task says file does not exist
I've made a custom MSBuild task to zip up the newly created .dll along with relevant files for release whenever the project is built. For some reason though, it says the newly created .dll does not exist... When the log literally shows its existence in the exact location like two line up:
CopyFilesToOutputDirectory:
Copying file from "/home/newmaz/Documents/HFF_ObjectGrabber/build/obj/ObjectGrabber/Debug/Debug/ObjectGrabber.dll" to "/home/newmaz/Documents/HFF_ObjectGrabber/build/bin/output/ObjectGrabber.dll".
ObjectGrabber -> /home/newmaz/Documents/HFF_ObjectGrabber/build/bin/output/ObjectGrabber.dll
ZipOutput:
Zipping build
File copied: /home/newmaz/Documents/HFF_ObjectGrabber/src/../README.md
File copied: /home/newmaz/Documents/HFF_ObjectGrabber/src/../icon.png
File copied: /home/newmaz/Documents/HFF_ObjectGrabber/src/../manifest.json
/home/newmaz/Documents/HFF_ObjectGrabber/src/ObjectGrabber.csproj(34,5): error : File does not exist: /home/newmaz/Documents/HFF_ObjectGrabber/src/../build/bin/output/ObjectGrabber.dll
CopyFilesToOutputDirectory:
Copying file from "/home/newmaz/Documents/HFF_ObjectGrabber/build/obj/ObjectGrabber/Debug/Debug/ObjectGrabber.dll" to "/home/newmaz/Documents/HFF_ObjectGrabber/build/bin/output/ObjectGrabber.dll".
ObjectGrabber -> /home/newmaz/Documents/HFF_ObjectGrabber/build/bin/output/ObjectGrabber.dll
ZipOutput:
Zipping build
File copied: /home/newmaz/Documents/HFF_ObjectGrabber/src/../README.md
File copied: /home/newmaz/Documents/HFF_ObjectGrabber/src/../icon.png
File copied: /home/newmaz/Documents/HFF_ObjectGrabber/src/../manifest.json
/home/newmaz/Documents/HFF_ObjectGrabber/src/ObjectGrabber.csproj(34,5): error : File does not exist: /home/newmaz/Documents/HFF_ObjectGrabber/src/../build/bin/output/ObjectGrabber.dll
Like, it just copied the file into the exact location it's complaining about Here's the relevant snippet of the ZipTask:
foreach (ITaskItem input_file in Files)
{
string file_string = input_file.ItemSpec;
if (File.Exists(file_string))
{
string file_to_zip = Path.Combine(directory_to_zip, Path.GetFileName(file_string));
File.Copy(file_string, file_to_zip, true);
Log.LogMessage("File copied: " + file_string);
}
else
{
Log.LogError("File does not exist: " + file_string);
return false;
}
}
foreach (ITaskItem input_file in Files)
{
string file_string = input_file.ItemSpec;
if (File.Exists(file_string))
{
string file_to_zip = Path.Combine(directory_to_zip, Path.GetFileName(file_string));
File.Copy(file_string, file_to_zip, true);
Log.LogMessage("File copied: " + file_string);
}
else
{
Log.LogError("File does not exist: " + file_string);
return false;
}
}
And here's the part of my project's .csproj that calls it:
<UsingTask TaskName="ObjectGrabberBuildTasks.ZipTask"
AssemblyFile="$(RootDir)\tasks\build\bin\tasks\ZipTask.dll"/>

<Target Name="ZipOutput"
AfterTargets="CopyFilesToOutputDirectory">

<ItemGroup>
<ZipFiles Include="$(RootDir)\README.md" />
<ZipFiles Include="$(RootDir)\icon.png" />
<ZipFiles Include="$(RootDir)\manifest.json" />
<ZipFiles Include="$(OutputPath)$(AssemblyName).dll" />
</ItemGroup>

<Message Importance="high" Text="Zipping build" />

<ZipTask Files="@(ZipFiles)"
OutputName="GrabCountTracker"
OutputLocation="$(SharedBuildDir)"
/>
</Target>
<UsingTask TaskName="ObjectGrabberBuildTasks.ZipTask"
AssemblyFile="$(RootDir)\tasks\build\bin\tasks\ZipTask.dll"/>

<Target Name="ZipOutput"
AfterTargets="CopyFilesToOutputDirectory">

<ItemGroup>
<ZipFiles Include="$(RootDir)\README.md" />
<ZipFiles Include="$(RootDir)\icon.png" />
<ZipFiles Include="$(RootDir)\manifest.json" />
<ZipFiles Include="$(OutputPath)$(AssemblyName).dll" />
</ItemGroup>

<Message Importance="high" Text="Zipping build" />

<ZipTask Files="@(ZipFiles)"
OutputName="GrabCountTracker"
OutputLocation="$(SharedBuildDir)"
/>
</Target>
Yes, I'm aware that there's no \ between the $(OutputPath) and $(AssemblyName), the $(OutputPath) property has the \ included, and you can tell in the error message that it's successfully adding a / between the directory and file name. Any thoughts?
44 replies
CC#
Created by 乙ᗰᗩᑎ350᙭ on 10/20/2023 in #help
✅ Get build output directory at compile time?
The current project I'm working on is a set of plugins to be run inside another application. When I first started, I would have to relaunch the application every time I made a change to my code, which took a while. Since then, I've added a new plugin to the DEBUG build of the project which monitors the Visual Studio output directory and, if it notices a change in any of the DLL files, will find and reload the plugin that changed without restarting the application. This has been a huge help. Now, in this plugin is the absolute path of the directory to monitor
public string buildDirectory = "C:\\Users\\Temp\\.......\\bin\\Output";
public string buildDirectory = "C:\\Users\\Temp\\.......\\bin\\Output";
This has worked great while on my desktop PC, but I'd like the ability to work on the project while on my laptop or other device. Ideally, this workflow would just involve pulling/pushing from GitHub w/o needing to manually change this one string on each device. Does Visual Studio have something like a OUTPUT macro that evaluates to the build directory at compile time or something of that nature? (yes, I know C# doesn't have C-style macros so this probably isn't the right terminology) And/or could I store the the value in something like path.txt which is in my .gitignore and is substituted into the string as a precompiler step or something of that nature? I don't think there's a way to do it at runtime, because the assembly won't be run in the build directory... Thanks!
6 replies
CC#
Created by 乙ᗰᗩᑎ350᙭ on 7/2/2023 in #help
❔ Loading a Unity Font object from an assembly's Embedded Resource
Well, I'm trying to load a font I have as a resource embedded in my C# assembly. I've tried a number of things, my most recent attempt seen here (ignore the bad variable names, I'll clean it up once I get it working):
Shell.print("=====FONTS=====");
string resourcePath = Assembly.GetExecutingAssembly().GetManifestResourceNames()[0];
Stream fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath);
var tempFiles = new TempFileCollection();
string file = tempFiles.AddExtension("otf");
using (FileStream fs = File.OpenWrite(file))
{
fontStream.CopyTo(fs);
}
unifont = new Font(file);
Shell.print(unifont.characterInfo.Length);
Shell.print("===END FONTS===");
Shell.print("=====FONTS=====");
string resourcePath = Assembly.GetExecutingAssembly().GetManifestResourceNames()[0];
Stream fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath);
var tempFiles = new TempFileCollection();
string file = tempFiles.AddExtension("otf");
using (FileStream fs = File.OpenWrite(file))
{
fontStream.CopyTo(fs);
}
unifont = new Font(file);
Shell.print(unifont.characterInfo.Length);
Shell.print("===END FONTS===");
The idea being that once I successfully load the font, it will print something other than 0. I have also tried passing the embedded "path" TextAdventure.Assets.unifont-15.0.06.otf straight to the Font constructor (both relative path & appended to the absolute path of the assembly). I have also put the .otf file in a Unity Asset Bundle and used AssetBundle.LoadFromStream(fontStream).LoadAsset<Font>("assets/unifont-15.0.06.otf") to try and grab the file. Any ideas?
40 replies