C
C#•2w ago
stigzler

Where are Build variables stored with .net Visual Studio Project Properties?

Hi. I'm making the onerous transition from developing in .net Framework to .net alone. Currently upgrading a load of projects and hit a snag. The project properties system is very different. I'm wanting to be able to change things before a build such as the Package Version. However, under ProjectProperties>Build, these seem to be stored in a tokenised format: $(AssemblyName) $(VersionPrefix) $(Authors) etc. I might not be looking hard enough - but where the hell does msbuild pull these vars from??
12 Replies
ero
ero•2w ago
from other parts in the project properties these should all be settable in a .net framework project, you might notice a Properties/AssemblyInfo.cs file. this is what stores, among others, package information like description, author, version, etc this file is no longer necessary in .net, it's generated from the project properties the project properties can be set and edited in the project file itself, or from the vs project settings. your project file might contain something like this, for example;
<Project Sdk="<sdk>">

<PropertyGroup>
<Authors>@stigzler</Authors>
</PropertyGroup>

</Project>
<Project Sdk="<sdk>">

<PropertyGroup>
<Authors>@stigzler</Authors>
</PropertyGroup>

</Project>
(other properties omitted) this property can then be reused in other properties in msbuild, accessing a property is done via $(PropertyName) that's what you might be seeing in the vs project settings when it accesses $(Authors), or $(AssemblyName)
stigzler
stigzlerOP•2w ago
Ah thanks for this. Done some more reading and think I would like to still use an AssemblyInfo.cs file rather than alter the project file every time as historically (with Framework) used a script to auto-update the ver number. Would rather not mess with the project file. Is there a way to auto-generate the AssemblyInfo.cs file as it's missing in my .net upgraded code
ero
ero•2w ago
i would very much recommend getting used to working with project files it's one of the major benefits of modern .net sdk versions sdk projects can access environment variables, for example
stigzler
stigzlerOP•2w ago
so - to manually adjust version - I would unload the project, alter the file and reload each time?
ero
ero•2w ago
you do not need to unload the project
stigzler
stigzlerOP•2w ago
Hmmm...changed it in Project Properties, also checked in proj file, not dice on the build - file version shows as 0.0.0.0
No description
No description
No description
stigzler
stigzlerOP•2w ago
No description
ero
ero•2w ago
can't say i repro, works for me
ero
ero•2w ago
No description
stigzler
stigzlerOP•2w ago
aha - had to change to this: <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
ero
ero•2w ago
You should be able to omit it, that's the default value
stigzler
stigzlerOP•2w ago
it was set to false for some reason 🤷 always knew this transition from framework to .net was goign to be a bumpy ride! thanks for your help

Did you find this page helpful?