-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Standard build variables are not replaced in before/after build scripts. #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Not sure if this is a SDK or a project system issue. @basoundr can you take a look? |
This is because the I think for this to work in the previous project system, you would have to set the build event properties after the CSharp.targets import at the bottom of your file. This isn't easy to do now that that import is implicit. In light of this, we may want to discourage or disable use of |
I'd love to disable use of the events in general for many reasons like this. Disabling them for Sdk projects gets a 👍 from me. |
Is there any solution for this? It is affecting us as well. We were also trying to change the Output path in the project settings, but clicking the Browse button crashes VS. |
You cant just decide to get rid of this. I think thousands of users all over the world use it. |
I'm still trying to find out when this will be fixed as we definitely need the pre/post build events to work and to properly pass in the macros/environment variables? |
@mgwalm @Ziflin I don't expect us to make Instead, what you can do is use targets to do this. Here's an example: <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo Before Build: $(OutDir)" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo After Build: $(OutDir)" />
</Target> |
@dsplaisted Thanks! That's all I was looking for. Is there a webpage somewhere that describes the new csproj format? |
@Ziflin I think some of the documentation is still a work-in-progress, but see https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/ and especially https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/csproj |
@dsplaisted Great! Thank you very much! |
This still doesn't work for things like $(ConfigurationName) either, and that is known before building. |
@StingyJack , if it helps this actually worked for me when combined with the solution in issue #1569 ( anwer from davkean ). The only drawback for me is that these |
With dotnet/project-system#2367, the Visual Studio UI will now emit targets for build customization, so adding new steps to new projects will allow use of any properties and items defined at the relevant point in the build. The new implementation does NOT update existing definitions of the *Event properties, so you might need to remove them and re-add them through the UI to get the updated behavior. If you already defined your own target, 1) 👍and 2) you shouldn't need to take any action, unless you really want to use the UI to manage the process. |
Is this the same issue as dotnet/project-system#1569 ? |
@DaveInCaz Not exactly. That bug was fixed when Visual Studio was taught to emit pre- and post-build events using a better mechanism that isn't subject to the constraints discussed here. However, it's still possible to manually use the property approach, which is subject to the ordering-of-property-definitions constraints that cause problems here. |
Well, yes. I dont really want to do all the typing required to unload, manually modify a proj file, and then reload it when I can do it in a few shortcut keys. I sure as heck dont want to type in full commands for anything. We didn't pay for Visual Studio so we could have notepad + msbuild.
That doesn't read very well.
The issue is that the things dont populate as expected. They are useful things to many people, and I dont see a compelling reason here to make all those users (customers) have to change what was working code before that is now not. |
Adding to @StingyJack's points... I have zero problem with build events being phased out and build targets being the new best practice, especially if the implementation is as simple as dsplaisted's answer above. All of us long-time Microsoft users could stand to get out of our comfort zone and write some code rather than having a magical UI take care of everything for us, and I love that the "new" Microsoft seems to be embracing more transparent tools that can be tweaked in any text editor, not just with mindless clicking. All that said, I have two problems with the current build-event situation:
|
@Rabadash8820 Projects using the new project system already get the some new behaviour: The UI will actually create targets. This was added in 15.3 - dotnet/project-system#2367. But AFAIK it doesn't switch from the build events to targets, but it will create and edit targets when you first use it. |
@dasMulli how does a version # like 15.3 which you mentioned correspond to what is available to a given version of Visual Studio? Thanks |
Just to chime in; an unfortunate aspect of using the XML hackery is the combination of quoted strings and Microsoft-style path delimiters. f.ex:
Embedding this into a XML string seems to just have re-opened that can of worms of incompatibility (between Windows and "everything else"), both when it comes to path separators and quoting in general (of both strings and whitespaces). Moving on, is this documented? I don't mean here, or in the code, I mean in an actual document, something a user of it can depend on. If run as part of a batch-build from .sln, whether from command-line or VS, is it possible to access properties of a different project? Example: I'm thinking of the scenario where you need A.exe to do pre- or post-processing for/of B.dll. Is it possible to access e.g. produced assembly name, to get full path to A.exe from B.csproj, or would you be forced to copy A.exe into a platform-specific known location and reference it using platform-specific pathnames? If not built as part of a batch-process it would obviously be impossible to reliably do such lookups. |
…0190603.1 (dotnet#677) - Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-preview6.19303.1 - Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-preview6.19303.1
It is also not possible to access TargetDir/OutDir like this as before it was:
but this works, but require several use in case other target need this
|
..and I've just run into a related issue with VS 2022. https://developercommunity.visualstudio.com/t/VS-not-saving-project-files/10170893?viewtype=all |
Why is this still an ongoing issue 6 years on? The events show up in the Events boxes in the new VS, but don't work as expected. You need to delete/copy out your code, clear the box and re-enter it for the Target to be created correctly. |
This helped me: https://stackoverflow.com/a/52977805/2287576 So now I have:
But:
|
Moving from https://github.com/dotnet/cli/issues/5095 on behalf of @mdekrey
Sorry if this isn't the right spot; I wasn't sure if the MSBuild repo was a better location for this report or not. Simplest steps are below, but I originally accessed this via Visual Studio, which gave menus for the "macro" variables that did not get replaced. Note that this occurs for both project variables, not just solution variables, as the example uses the dotnet cli.
Steps to reproduce
dotnet new
).csproj
to have PreBuildEvent or PostBuildEvent that uses build variables as documented in previous C# projects. For example:dotnet restore
)dotnet build
)Expected behavior
Standard build variables should be replaced in before/after build scripts.
Actual behavior
Standard build variables are not replaced in before/after build scripts.
Environment data
dotnet --info
output:The text was updated successfully, but these errors were encountered: