Build macros in VS

This forum is meant for questions and discussions about the X# language and tools
Post Reply
JohnBonnett88
Posts: 51
Joined: Mon Mar 07, 2022 12:34 am

Build macros in VS

Post by JohnBonnett88 »

Hi All,
I am having a problem with defining some build macros for an X# project in VS2022, in particular where I want the output to go. When I select the Properties of the project and go to the Build tab, I see the snippet in attachment P1.
P1.png
P1.png (4.2 KiB) Viewed 813 times
Now I don't know what an Intermediate Output Path means or is, and I don't know what the macro names shown here are. They do not appear in the editor/browser you get when you click the three dots button at the right. So I change things to be what I want as shown in attachment P2.
P2.png
P2.png (2.93 KiB) Viewed 813 times
I build and I get, in the output window:

Build started...
------ Build started: Project: 1 bDefines, Configuration: Release Any CPU ------
1 bDefines -> C:UsersXVJBONNEsourcereposLabProRelease1 bDefines.dll
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

It has generated the output exactly where I wanted. I should be able to do this with two macros like this
$(SolutionDir)$(ConfigurationName)
but that does not seem to work. It puts the output in the folder one level higher for some reason.

I close the solution, open it again and go to the same Properties/Build for the project again and what I see is back to P1 again.

If I look at the project file in an external editor, it has an entry like this:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" Label="Configuration">
<PlatformTarget>x86</PlatformTarget>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<EmitDebugInformation>false</EmitDebugInformation>
<DebugType>pdbonly</DebugType>
<OutputPath>$(SolutionDir)Release</OutputPath>

and the OutputPath is just what I want, but is not what I see in VS.

What is happening here?

Best Regards,
John Bonnett
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Build macros in VS

Post by robert »

John,
First: VS/MsBuild uses a 2 step approach when building. This usually involves the Obj and the Bin folder.
The Obj folder is used to store the compilation result but also some intermediate files, such as compiled resources and cache files for dependency information. This folder also contains the generated source code for XAML files and other source code that is generated by the build system.
After the compilation the compiled DLL, PDB and/or XML are copied to the output folder, along with any files that are marked as "copy to output".
I am not sure why you are seeing the $(OutputPath) macro in the dialog. This is not correct. It should have returned exactly what you typed in. Which version of X# are you using ?

If you leave the intermediate output path empty then the temp files will go to the obj$(Configuration) folder under the project.

The macro $(SolutionDir)$(ConfigurationName) is not correct. This should be $(SolutionDir)$(Configuration)

Pro tip:
You can also define your own properties in the project file.
That is not possible through the Project Properties screen but you need to directly edit the XSProj file.
For example in our VS integration system we are including a common file "Common.Props" in each project file

Code: Select all

<Import Project="$(SolutionDir)ToolsCommon.props" Condition="'$(SolutionDir)'!=''" />
In that Common.Props file we declare a lot of properties. A subset is shown below
The full file can be seen here:
https://github.com/X-Sharp/XSharpPublic ... mmon.props

Code: Select all

<PropertyGroup>
<VSTarget Condition=" '$(VSTarget)' == '' ">2019</VSTarget>
.
<BinariesDir>$(SolutionDir)Binaries$(VSTarget)</BinariesDir>
<IntermediateOutputPath>$(BinariesDir)obj$(Configuration)$(ProjectName)</IntermediateOutputPath>
<OutputPath>$(BinariesDir)$(Configuration)</OutputPath>
.
</PropertyGroup>
In the projects inside the solution we are no longer declaring the OutPutPath and IntermediateOutputPath.
These are all set in the included Common.Props file.That is very convenient.
Of course you will have to edit these properties directly in the xsproj file then and do not use the property dialog.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
JohnBonnett88
Posts: 51
Joined: Mon Mar 07, 2022 12:34 am

Build macros in VS

Post by JohnBonnett88 »

Hi Robert,

Wow! Thankyou for such a comprehensive reply. I had discovered some of the things you mention in my digging around but X# seemed to be behaving rather differently than C#, which I also have in my solution, in particular that difference with ${Configuration} and ${ConfigurationName}. I only used ${ConfigurationName} because it appeared in the list of macros when I went to edit the output path. I didn't know why X# should be different, but thought I should follow that guidance.

I will certainly look into that Common.Props, now that I know about it. I had noticed that menu option in X# projects that let you edit the project file directly, and the fact that C# does not have it.

Thankyou again for all your effort and ongoing help.

Best Regards,
John
JohnBonnett88
Posts: 51
Joined: Mon Mar 07, 2022 12:34 am

Build macros in VS

Post by JohnBonnett88 »

Hi Robert,
I noticed I did not reply to your question about version. I am on V1.12.2. I see there is a V2.13, but not quite public yet.
John
JohnBonnett88
Posts: 51
Joined: Mon Mar 07, 2022 12:34 am

Build macros in VS

Post by JohnBonnett88 »

Hi All,

I got my Release build outputs going where I wanted by manually editing my *.xsproj like this:

The change was to make sure that, in the PropertyGroup that defines the Release build, you have the OutputPath defined as shown below.

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" Label="Configuration">

<OutputPath>$(SolutionDir)$(Configuration)</OutputPath>

</PropertyGroup>

There are other lines in the group of course.

Even though that macro $(Configuration) does not show up when you try to edit the output path in the Properties dialog in VS, it seems to do the what I wanted. In the dialog it still shows $(OutputPath) for that path, contrary to what is in the project file.

Best Regards,
John Bonnett
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Build macros in VS

Post by robert »

John,
Can you send me your XsProj file so I can see what the problem is with the $(OutputPath) in the dialog ?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
JohnBonnett88
Posts: 51
Joined: Mon Mar 07, 2022 12:34 am

Build macros in VS

Post by JohnBonnett88 »

Hi Robert,

Sorry I did not notice your reply earlier, but better late than never I suppose. I have attached one of my xsproj files, with the extension changed to keep the mail system happy.

The project files were mostly just as the Xporter created, although I had to play with references quite a bit to get everything linked up as required. It was only recently, when I had got things to a clean build stage, that I needed to adjust where the outputs were going and play with build macros.

Best Regards,
John
Attachments
LabPro1.txt
(61.1 KiB) Downloaded 93 times
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Build macros in VS

Post by robert »

John,
Did you forget to add the attachment ?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
JohnBonnett88
Posts: 51
Joined: Mon Mar 07, 2022 12:34 am

Build macros in VS

Post by JohnBonnett88 »

Yes I did. Should be now
LabPro1.txt
(61.1 KiB) Downloaded 103 times
John
Post Reply