MSB3073 exited with code 3 - Post Build Event in Visual Studio 2017 - visual-studio

I am trying to perform registration of the DLL which was created during Build.
In project properties -> Build Events -> Post-Build-Event i have added the below command to perform registration,
regsvr32 /s /c "$(TargetPath)"
This command is used to perform registration of the DLL specified in Target Path.
When i try to Build my code, i am facing following error,
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(138,5):
error MSB3073: The command "regsvr32 /s /c "D:\Project\Debug\x64\SDK.dll"
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(138,5):
error MSB3073: :VCEnd" exited with code 3.
On clicking the error, it navigates to below tags within Microsoft.CppCommon.targets
<Target Name="PostBuildEvent" Condition="'$(PostBuildEventUseInBuild)'!='false'">
<Message Text="%(PostBuildEvent.Message)" Condition="'%(PostBuildEvent.Message)' != '' and '%(PostBuildEvent.Command)' != ''" Importance="High" />
<Exec Command="%(PostBuildEvent.Command)$(_BuildSuffix)" Condition="'%(PostBuildEvent.Command)' != ''"/>
I searched for error MSB3073: :VCEnd" exited with code 3 in few links and found that it occurs when the path specified is invalid or could not be found.
However, the path of the DLL was in the location i specified. I even tried to provide absolute path of DLL within the Post-Build-Event. Yet i'm facing same error.
Am i missing something while performing Post-Build-Event or is there anything to do with regsvr32 command?

MSB3073 exited with code 3 - Post Build Event in Visual Studio 2017
The issue is related to your dynamic library project and not related to VS.
And when you want to register a com dll, the dll project should contain a ID to register into system. However, the dynamic library project does not have the ID by default. So this type of project cannot used as DLLs that will to be registered.
If you still want to use dynamic library project, you should implement DllRegisterServer to add the ID.
You can use ATL projects which contain the ID as dll projects .
This is a similar issue about it.
Solution
1) Instead, you should create ATL projects.
2) Then, in the command, you should remove /c which was abandoned so far.
Or use like this command:
regsvr32 /n /i "$(TargetPath)" as command in post-build event.
=====================
Update 1
Since your project is an old WRT project, you can just create a new WRT runtime component project in VS2017 and then migrate the content of your old project into the new one. It will save you a lot of time and avoid a lot of tedious mistakes.
1) Please install C++/WinRT vs extension first.
2) Then create a new windows runtime componment project and then migrate your old project's content into the new one.
In my side, the project can works well with command regsvr32 /n /i "$(TargetPath)".

Related

How to handle post-build events in an Azure pipeline?

I can build a solution locally and in one project I have post-build events:
xcopy "$(SolutionDir)pluginfolder\bin\Debug\net48\pluginname.*" "$(TargetDir)" /Y
I do this because the target project doesn't have a reference to the plugin projects.
Now I'm trying to move to an Azure pipeline. I created an MSBuild task that builds just the target project and not the complete solution, and I get the following error on running in a self-hosted agent:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5266,5): Error MSB3073: The command "xcopy "Undefinedpluginfolder\bin\Debug\net48\pluginname.*" "C:\agent_work\5\s\myproj\bin" /Y ended with Code 4.
What is the best approach to solve this issue?
"Undefinedpluginfolder\bin\Debug\net48\pluginname.*"
The $(SolutionDir) is recognized as Undefined, this is because msbuild has no knowledge about the solution when building a single project.
As workaround, you can insert the following script above the script of PostBuild event. Something like:
<PropertyGroup>
<ProjectFolder>$([System.IO.Directory]::GetParent($(ProjectDir)))</ProjectFolder>
<MySolutionDir>$([System.IO.Directory]::GetParent($(ProjectFolder)))\</MySolutionDir>
It's recommended to add my script and PostBuildEvent in same propertyGroup
<PostBuildEvent>echo $(MySolutionDir)</PostBuildEvent>
</PropertyGroup>
Command line:
xcopy "$(MySolutionDir)pluginfolder\bin\Debug\net48\pluginname.*" "$(TargetDir)" /Y
You can refer to this ticket with similar issue.

Build specific Visual studio project under project solution using Msbuild and devenv

I have Visual studio project solution which has multiple .csproj. Each .csproj has some reference libraries.The project settings are made in such a way the reference libraries are built first and then .csproj is built. This works as expected when i run it in visual studio IDE. But when i try to execute using msbuild i'm getting an error saying target doesn't exist. Gone through many posts related to this issue ,tried possible things.But didn't built.Looks like i might be doing something silly or missing something in the settings.
Also tried using devenv from commandline. With this option i dont see any error but at same time the project doesnt build.I dont see any message after execution of command.Im using visual studio 2015
Here is my project structure
Poject.sln
ProjectA
porjectB
projectC
Libraries
libA
libB
msbuild "project.sln" target:"D:\Projects\Source\Demo\ProjectA\ProjectA.csproj" /t:build
"/p:Configuration=Debug" "/p:platform=x86"
I see the below error
"D:\project.sln" (D:\Projects\Source\Demo\ProjectA\;build target) (1) ->
D:\project.sln.metaproj : error MSB4057: The target "D:\Projects\Source\Demo\ProjectA" does not exist in the project. [D:\project.sln]
Here is the command used using devenv
devenv.exe "project.sln" /build Debug /project `"D:\Projects\source\Demo\Applications\ProjectA\ProjectA.csproj" /projectconfig Debug
After executing the above its doesnt build and i dont see any error too.
error MSB4057: The target "D:\Projects\Source\Demo\ProjectA" does not
exist in the project.
The error indicates your path in command is not valid and project.sln can't recognize the path. So you actually meet one path-related issue. And you should pass the ProjectA to the targets argument instead of ProjectA.csproj! More details see tip3 in For MSBuild.
For MSBuild:
1.If you're only trying to build ProjectA and its reference libraries.
Navigate(cd) to path where ProjectA.csproj exists, and then use command msbuild ProjectA.csproj /t:build /p:Configuration=Debug /p:platform=x86
Also you can directly use command msbuild AbsolutePath\ProjectA.csproj /t:build /p:Configuration=Debug /p:platform=x86. It's not necessary to use " to cover the path and arguments.
(ProjectA.csproj file should have definitions about the reference to those two library projects, so msbuild ProjectA.csproj will build those two projects first. You don't need to specify the xx.sln in your command.)
2.If you're trying to build whole solution(all the projects):
msbuild project.sln /t:build /p:Configuration=xxx /p:platform=xxx
Navigate to solution folder when you run above command, or use absolutepath\project.sln with that command.
3.When you want to build specific projects(more than one) in solution:
Check How to: Build Specific Targets in Solutions By Using MSBuild.exe. Since you're only build ProjectA, you don't need to use this format. For example: Only when you need to build both ProjectA and ProjectB, but not build ProjectC... You can use command like:
msbuild xxx.sln /t:NotInSlnfolder:Build;NewFolder\InSolutionFolder:Build
Pay attention to the path when you use this format. Whether your project is in solution folder can affect the build result a lot ! And, the direct cause of your issue, this command's targets argument needs one ProjectName as input instead of ProjectName.csproj.
For Devenv command:
1.I always use VS2017 and VS2019,so I'm not certainly sure if VS2015's devenv related command has big difference from VS2017's or VS2019's. But according to details from this VS2017 document:
Commands that begin with devenv are handled by the devenv.com utility, which delivers output through standard system streams, such as stdout and stderr.
Alternatively, commands that begin with devenv.exe can use the same switches, but the devenv.com utility is bypassed. Using devenv.exe directly prevents output from appearing on the console.
I think that's why you don't see any message after execution of command. You should use devenv.com command to see the output in console. And it's by design that devenv.exe will prevents output from appearing on the console.
2.The following command builds the project CSharpWinApp, using the Debug project build configuration within MySolution.
devenv "%USERPROFILE%\source\repos\MySolution.sln" /build Debug /project "CSharpWinApp\CSharpWinApp.csproj" /projectconfig Debug
More details about devenv reference please check this document.
In addition:
1.Looks like you have one strange project structure. I checked your error message above and it seems your several projects(xx.csproj) are not under Solution(xx.sln) folder. Just a suggestion, the normal folder structure for VS2015 is always:
Solution folder
xx.sln
ProjectA folder
ProjectA.csproj
ProjectB folder
ProjectB.csproj
2.For most of the projects, build using msbuild is more powerful and convenient than build using devenv. So if you don't have special reason, I recommend using Msbuild, the build engine of VS.
Hope all above helps to resolve your issue and puzzle. Let me know if your issue persists:)
File "/Users/morel893/Desktop/env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "projects_project" does not exist
LINE 1: ...ct"."technology", "projects_project"."image" FROM "projects_...

Why is $OUTDIR$ duplicating part of the path

I am using the following line in my Post-build event command line in VS2017:
xcopy /d /y "$(ProjectDir)dll\*.dll" "$(OutDir)"
to move dlls to the \bin\Debug folder when building. However the dlls in the dll directory end up in the folder \bin\Debug\bin\Debug. $(OutDir) is set to \bin\Debug. I have not touched or changed that from the default project generated. What reason would cause the path to be duplicated like that?
For this dll, I am unable to add it as a reference because it VS does not seem to support it (gives an unsupported/invalid error when I browse and add it). The dll does interface well in C# despite that.

devenv.com won't start without a desktop session

I'm setting up a Jenkins job for a Windows 10 application.
I need to compile one of the four projects inside the solution with devenv.com executable because it is a project with .vdproj extension (setup project).
The other projects are built successfully with MSBuild without any problem.
The Jenkins job ends successfully when I'm logged in as root on a Jenkins target node, but, fails when I run the job from Jenkins and I'm not logged in.
Need your help or workaround to solve the issue.
PS: we are using ant as task runner and we have a specific task that start the build process.
EDIT 26/01/2017
I would like to provide you other informations like the error message and one step that I've skipped before.
The error message provides a link to a Microsoft Page and reports a configuration problem.
As solved by this StackOverflow post, I've added a new DWORD registry key under
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0_Config\MSBuild\EnableOutOfProcBuild
Can the problem be that this value can't be readed when the User is'nt logged in ?
EDIT 27/01/2017
I'm going crazy with this issue.
The command devenv /? work fine when i run it locally but wont work when i run it from Jenkins with the same error as before: Microsoft Visual Studio found a configuration problem. To fix it restart as administrator or visit http://go.microsoft.com/fwlink/?LinkId=659046 for further information.
So the devenv.com cannot be executed when i'm not logged in ??
UPDATED 31/01/2017#
Here's my .bat file called from a target by ant build.xml
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
#set MSBUILD="C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe"
%MSBUILD% "%cd%\src\AutomatedSetupBuild.proj"
pause
Where the AutomatedSetupBuild.proj is an MSBuild script
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="Build">
<PropertyGroup>
<DevEnv>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com</DevEnv>
<SolutionFile>$(MSBuildProjectDirectory)\MySolution.sln</SolutionFile>
<ProjectFile>MySetupProject\MySetupProject.vdproj</ProjectFile>
<Configuration>Release</Configuration>
</PropertyGroup>
<Exec
Command=""$(DevEnv)" "$(SolutionFile)" /Rebuild "$(Configuration)" /Project "$(ProjectFile)" /ProjectConfig "$(Configuration)" /Log vs.log /useenv"
ContinueOnError="false"
IgnoreExitCode="false"
WorkingDirectory="$(MSBuildProjectDirectory)" />
</Target>
</Project>
As you can see, I'm loading the environment variable before run devenv.com but i receive the same error.
Do you use a free style job or do you use a Jenkinsfile for a pipeline project? In any case, for devenv.com to work, environment variables have to be set up.
Please go to the Windows start menu and look for something like Visual Studio XX -> Visual Studio Tools -> Developer Command Prompt for VS20XX. Press right mouse bottom and select properties. There look for target. In my case this field contains the following string:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat""
If you use e.g. a Jenkinsfile, change the call to devnenv.com, which probably looks like
bat "devenv.com my_solution_file.sln /project my_project /build \"Release|x64\""
to
bat "call \"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat\"; devenv.com my_solution_file.sln /project my_project /build \"Release|x64\""
It is important, that the call to the VsDevCmd.bat is within the same bat command. Otherwise the environment variable settings get lost and are not seen by a second call to bat.
Open the dev command prompt type "where devenv" then call the full path with the .com version... e.g.
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.com" /Rebuild "RELEASE|Win32" "F:\project.sln"
For my part, I had to convert the Visual Studio 2015 SSRS project to SSRS Visual Studio 2017. Then I installed the 2017 SSDT for VS 2017, and use MSBUILD. Everything works well without open remote session.

msbuild error: The property DirectoryName does not exist or was not found

This is my first attempt to configure an automated build on Visual Studio Online.
After creating a new build, I queued it to run. The first step was successfully completed (Get sources). Now I am experiencing and error in the build step. Here is a small snippet including the message:
782 2015-08-31T16:30:52.4324803Z Executing the powershell script:
C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\tasks\VSBuild\1.0.13\VSBuild.ps1
783 2015-08-31T16:30:54.0509690Z ##[error]The property DirectoryName
does not exist or was not found.
784 2015-08-31T16:30:54.1321607Z C:\Program Files
(x86)\MSBuild\14.0\bin\msbuild.exe "C:\a\5bc0b6a3\MySolution" /nologo
/m /nr:false /fl /flp:"logfile=C:\a\5bc0b6a3\MySolution.log"
/dl:CentralLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
/p:platform="any cpu" /p:configuration="debug"
/p:VisualStudioVersion="14.0"
785 2015-08-31T16:30:54.2859104Z MSBUILD : error MSB1009: Project
file does not exist.
I have searched for the DirectoryName string in the entire solution with no success and have now idea what it means.
Compilation works fine on my PC and I have no clue where to start looking at.
Any ideas?
You're missing the real error:
785 2015-08-31T16:30:54.2859104Z MSBUILD : error MSB1009: Project file does not exist.
You need to specify the path to a solution file. You can see that you're not:
C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
"C:\a\5bc0b6a3\MySolution" /nologo /m /nr:false /fl
/flp:"logfile=C:\a\5bc0b6a3\MySolution.log"
/dl:CentralLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
/p:platform="any cpu" /p:configuration="debug"
/p:VisualStudioVersion="14.0"
You can just specify **\*.sln for the "Solutions" parameter and it will discover and build all of the solutions in the workspace you mapped. If you need to get more specific, you can do that as well.
The folder in which the solution file is should be in or below one of the paths as defined in the mappings under the 'Repository' tab, otherwise the 'Project file does not exist' error will show up also.

Resources