I'm trying to automate obfuscation by using post-build commands in Visual Studio 2015. I've followed the steps from this article on MSDN.
I've added the post-build command as mentioned in steps and created Dotfuscator.xml, placed in root directory i.e. where vbproj file is located.
Once I build the project I get following error message.
Here is the post-build command:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\PreEmptive Solutions\Dotfuscator and Analytics Community Edition\dotfuscator.exe" /q /p=SourceDirectory=$(TargetDir),SourceFile=$(TargetFileName) $(ProjectDir)Dotfuscator.xml
Any hint or solution will be appreciated.
You need to quote those paths you are passing...
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\PreEmptive Solutions\Dotfuscator and Analytics Community Edition\dotfuscator.exe" /q /p=SourceDirectory="$(TargetDir)",SourceFile="$(TargetFileName)" $(ProjectDir)Dotfuscator.xml
Or Perhaps
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\PreEmptive Solutions\Dotfuscator and Analytics Community Edition\dotfuscator.exe" /q /p="SourceDirectory=$(TargetDir),SourceFile=$(TargetFileName)" $(ProjectDir)Dotfuscator.xml
Test it by running the exe from the command prompt to see how the thing handles that argument.
Now that you've sorted out the quoting issue as Trevor described, I think the next issue is that you're probably running a version of Dotfuscator that doesn't have command-line support.
Visual Studio 2015 Update 3 (and VS 2017) includes a version of Dotfuscator Community Edition (CE) that has command-line support. (You have to register to enable it.) If you're using an earlier version of VS 2015, you can download a version of Dotfuscator CE that has command-line support from PreEmptive; see the instructions here for details.
Full disclosure: I work for PreEmptive Solutions.
With the help of answers from #Trevor and #Nathan, here I'm able to achieve what was desired.
First I created the Dotfuscator.xml file using Dotfuscator.exe. Providing input files and generated obfuscated DLL once.
Once it's confirmed that the XML file working fine, I then added following post build event build command
dotfuscatorCLI.exe "$(ProjectDir)Dotfuscator.xml"
Another way to achieve same results
Above solution will work but it would be specific to one computer. So if you are working in a team and there are chances that you build your solution on multiple machines then I would prefer the approach defined in the article whose link was shared in my Question. However that approach requires a minor tweak.
Here is the post build command that will work:
dotfuscatorcli.exe /q
/p=SourceDirectory="$(TargetDir)\",SourceFile=$(TargetFileName)
"$(ProjectDir)Dotfuscator.xml"
Please note here the Dotfuscator.xml is the one that is referred in the MSDN article, not the one generated by dotfuscator.exe as mentioned in previous solution. Also note, if your TargetFileName contains spaces then put double quotes around it.
Hope this would help others.
Related
I am getting this error on my CI server:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\WCF\Microsoft.VisualStudio.ServiceModel.targets" was not found
It seems my WCF service library project references that file, but the VisualStudio folder on Program Files\MSBuild\Microsoft doesn't contain a WCF folder.
I guess I need to install something on the server.
What do I need to install?
Well this ruined my morning, but let's not allow it to ruin anyone else's. I couldn't find this information anywhere else. You need to copy a few files from a development machine with VS Pro 2012.
As aphexddb mentions, you need to copy some targets from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\WCF to the same location on your CI server.
This then references an assembly called Microsoft.VisualStudio.ServiceModel.Core. You can find this assembly in either the GAC or in the IDE directory at C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE.
Copy this to your CI server and execute gacutil.exe -i Microsoft.VisualStudio.ServiceModel.Core.dll
This was enough to fix it for me.
This isn't the first time I found targets missing from my VS express install in my CI server. I can't help but feel that there is some sort of package I can download from somewhere that fills all this in. Does anyone know of such a thing? If not, perhaps we should create one.
Can still happen on vs2019
error MSB4019: The imported project "C:\Program Files (x86)\Microsoft
Visual
Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0\WCF\Microsoft.VisualStudio.ServiceModel.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
WCF is not installed by default as part of 'ASP.NET and web development' workload. To fix this,
On visual studio installer > modify > individual components tab, search for wcf, check, modify - the .targets file gets now installed, msbuild builds ok.
MSBuild auto-detection: using msbuild version '16.3.2.50909' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin'
I ran into this with Visual Studio 2017, for me the resolution was to modify my installation of Visual Studio to include the Windows Communication Foundation components.
Extract this file into folder
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\WCF
The file name is "Microsoft.VisualStudio.ServiceModel.targets"
Now you can solve the problem using the Nuget Package MSBuild.Microsoft.VisualStudio.Web.targets
so the build process does not require any change to the build server.
Install-Package MSBuild.Microsoft.VisualStudio.Web.targets
Details:
remove the element for "ServiceModels.targets" in the .csproj file
remove the target WebApplication from the build command (in yaml)
Ran into this same issue. Did the following to resolve:
Installed the Microsoft Web Platform Installer
Copied Directory "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\WCF" from dev laptop with Visual Studio 2012 to the build server
I've had the same error - my issue was that MS has modified the way MSBuild looks for the versions of VS in the build process template.
Make sure to use the right build process template.
If using TFS2013 and VS2013 use TfvcTemplate.12.xaml
I ran into this same error. In my case, the problem was that my Visual Studio 2008 project didn't get upgraded correctly, probably due to files being marked "read-only" by my source control. To fix it, I loaded the solution in Visual Studio 2015 with everything checked out.
The specific line in the .csproj file changed from
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\WCF\Microsoft.VisualStudio.ServiceModel.targets" />
To
<Import Project="$(WcfServiceModelTargetPath)\Microsoft.VisualStudio.ServiceModel.targets" />
If you are using VS 2022 build tools, it is no longer in the individual components section. It is on the first tab "Workloads", included in ".NET desktop build tools", you will see it in the list on the right-hand side when you select it.
I have a CruiseControl .NET build server running on Windows Server 2003, and I am trying to build and publish my ClickOnce application using msbuild.
Everything is working fine, except when I enable the bootstrapper of my ClickOnce application. When this happens, I get the following error in the DeploymentGenerateBootstrapper target:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (3939,9):
error MSB3147:
Could not find required file 'setup.bin' in 'E:\Projects\src\TestProject\Engine'.
.NET Framework 3.5 SP1 and 4 and latest Windows SDK for both are installed on the server, but the bootstrapper folder in C:\Program Files\Microsoft SDKs\Windows\versionNo\ does not exist. I tried copying the files from my workstation machine with no luck.
I do not want to install Visual Studio on server and only install the necessary SDKs.
I have also tried copying the bootsrapper folder from my machine
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper
to build server but no luck.
Any ideas?
You will also have to add the associated key and value to the registry to allow MSBuild to find the path to the Bootstrapper folder. I can confirm that this has worked for me using the following regedit.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\4.0]
#="0"
"Path"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bootstrapper\\"
Update: According to Emma's TFS Blog it appears the following registry values are checked in order to find the bootstrapper path and if not found looks in your local project folder under the Engine sub folder and then bails with the MSB3147 error if not found there.
HKLM\Software\Microsoft\GenericBootstrapper\<.NET Tools Version>\
HKLM \Software\Microsoft.NetFramework\SDKInstallRoot\Bootstrapper
HKLM \Software\Microsoft\VisualStudio\\InstallDir\Bootstrapper
Reminder: Also remember that there is a 32-bit and a 64-bit registry so be sure to add this value to the same registry that your tools will be accessing.
In the meantime I've also created a feature request to get a more reasonable solution for this issue. Please vote on my feature request to get Microsoft to take a look at it.
BTW, here are a few more links about this issue:
http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/7672078f-f2bd-4142-b8a9-740c2a8a5ae7
http://social.msdn.microsoft.com/Forums/en/msbuild/thread/6964ba78-5b66-4cd1-bdd1-b31edb76b96a
http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/97ac8717-daf7-4554-8dfa-8a63da47a17d
MSBuild: error MSB3147: Could not find required file 'setup.bin'
https://connect.microsoft.com/VisualStudio/feedback/details/361924/remove-bootstrapper-from-microsoft-sdks-directory
http://blogs.msdn.com/b/emmamou/archive/2009/04/08/team-build-for-clickonce-application-with-bootstrapper.aspx?CommentPosted=true#commentmessage
You can also pass the location of the bootstrapper packages to the common Publish target like this:
<PropertyGroup>
<BootstrapperSdkPath>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper</BootstrapperSdkPath>
</PropertyGroup>
and then
<Target Name="Publish">
<MSBuild Targets="publish" ... Properties="GenerateBootstrapperSdkPath=$(BootstrapperSdkPath); ..."/>
</Target>
I struggled with the same problem on my win7 x64 machine. I have not installed Visual Studio and tried to build and publish a .NET 4.5 WPF solution. I had to add the following keys to the registry
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\GenericBootstrapper\11.0]
"Path"="C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\Bootstrapper\\"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\GenericBootstrapper\4.0]
"Path"="C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\Bootstrapper\\"
You also need to copy the Bootstrapper folders from your dev machine. This blogpost directed me in the right direction http://www.wiktorzychla.com/2013/11/msb3147-could-not-find-required-file-on.html
I had a similar issue to this but in my case I do have Visual Studio installed on the box, and publishing from Visual Studio works fine.
When publishing from the command line with msbuild.exe, the build failed with aforementioned error "MSB3147 Could not find required file 'setup.bin'".
The solution was to explicitly specify what version of Visual Studio to use during build.
<MSBuild
Projects="MyProject.csproj"
Targets="publish"
Properties="Configuration=Release;PublishUrl=C:\AnyFolder;VisualStudioVersion=12.0"/>
I have Visual Studio 2013 on a Win7 x64 machine. My reading of the problem is that MSBuild was looking in the wrong place in the registry. By explicitly telling MS Build to use VS 12.0, it picked the correct registry location entry and consequently the correct path to BootstrapperSdkPath.
I was able to fix this problem by pointing to MSBuild.exe from this location
C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe
Previously I was pointing to
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Hi I know this answer its soooooo late but just in case
I had to add the Path prop to the task, with the Path where the bootstrapper its located, in my case I used Visual Studio 2015 so the Path is:
**Program Files(x86)\Microsoft Visual Studio 14.0\SDK\Boostrapper**
MSBuild has a Task GenerateBootstrapper in my case
<GenerateBootstrapper>
AplicationFile="$(AppName)"
ApplicationName=..
ApplicationUrl=..
BootstrapperItems=..
Culture=..
ApplicationUrl=..
Path="Program Files(x86)\Microsoft Visual Studio 14.0\SDK\Boostrapper\"
</GenerateBootstrapper>
with this the MSBuild is able to recognize and generate the file
Now i'm stucked with the .net 4 bootstrapper but guess is another story...
I experienced this same error via my TeamCity build server. The cause in my case was that I was running an MSBuild task against my .sln file, with a 'MyProject:publish' target. In this case, the solution+projecth had been updated to target .NET v4.5, but the build server was still configured to use MSBuild Tools 4.0 and .NET v4.0.
Took me a little while to work out the inconsistency between working and non-working branch builds.
I added this line to script. It helped.
call "%VS120COMNTOOLS%vsvars32.bat"
Visual Studio 2013, SDK v8.1A.
Just struggled with this myself - I chose to commit the bootstrapper files to source control. It is possible to override the path to bootstrappers, just provide /p:GenerateBootstrapperSdkPath=.build\Bootstrapper
Then no need to modify registry - and the added benefit that the build is now self-contained.
Only "problem" is that I have to manually copy the Bootstrapper files into source control. In my case (VStudio2015), this meant copying the files from C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper
I have a Visual Studio solution file (.sln), with several projects (VB.NET and C#, .vbproj, and .csproj files, respectively), and I have a Windows application, and I use ClickOnce to publish it.
Now, I need automate the Publish option using MSBuild or another good solution (cmd, VBScript, or BAT scripts).
How can I do it?
Well, ClickOnce uses MSBuild to publish itself. Therefore I would recomment to use MSBuild for your build-automation. See the reference on MSDN.
The first step is easy. You just run MSBUild with 'Publish'-target from the console. The settings made in Visual Studio are applied.
However, there are some tricky bits. For example, when you run it from the command line, the version number isn't increased. In my project I've solved this by passing the version-number from the build script.
Another tricky-part is when you want to run the build script on your build-server without Visual Studio installed. There you might have to copy some to make it work.
Is it possible to do this natively without addons or 3rd party tools?
I know there is the gacutil, but there is not an exe to run, otherwise i could've called it from the Exec task.
Has anyone done something similiar?
You should use the "GacUtil" task, from MSBuild Community Tasks (free).
I think this is cleaner than calling the executable.
Gacutil.exe is the standard supported tool for doing "dev box" installations of .NET assemblies. I would recommend simply using the Exec task as you mentioned to invoke it if you want to GAC your assemblies as part of a build task.
If you really want to do this without creating a new process, then you'd have to write a custom MSbuild task to implement the COM interop calls required to do what gacutil.exe does. Junfeng Zhang's blog post would be a good starting point if you want to go this route.
The gacuti.exe can be in more than one place. It's not on the system %path% variable, so you'll have to use the full path (it will not run otherwise).
I use C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\:
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -i MyAssembly.dll
It was reported to be found on other locations as well:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe
C:\Program Files\Microsoft Visual Studio 9.0\VC\gacutil.exe
An easy way to find it is using the windows search, or the command line: dir gacutil.exe /s /a.
Unfortunately, I have seed some servers where gacutil wasn't found, and I had to install the dlls manually.
I read quit a few Stackoverflow Questions about building mergemodules via commandline but all of them were accepted when either somebody suggested to use devenv for compilation or use Dark to create wix-files from existing msi files.
Considering the following:
VisualStudio isn't installed on the buildserver I have to use.
I am using nant + msbuild to compile the solutions
I would like to compile mergemodules from .vdproj (because Visual Studio detects dependencies automatically)
and create a msi setup from multiple mergemodules
... how can I build the merge modules from commandline without devenv and without loosing the comfort of automated dependencie resolving for mergemodules in visualstudio?
Maybe there is a nanttask for it I haven't found?
MSBuild doesn't support Visual Studio deployment projects, my advice would be to bite the bullet and go with Wix.
Perhaps VS2010 will use MSBuild schema for vdproj files? I'm guessing no, but couldn't find any links.
currently, it is not possible to do this with msbuild. but i am pretty sure you might be interested in this MSDN blog article because of your question related to merge module/setup projects in vs. It seems they won't continue to support .vdproj files in upcomming versions of visual studio (2010 will be the last supporting them).
So you may run into problems in the future even if you're using devenv instead of msbuild.
... but this article could be some kind of whispering, too. Anyway, there are a lot of alternatives on the road if you want to build setups.
Even I was facing the same issue. Use below format
call "C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\vcvarsall.bat"
cd /d Path_to_sln
"C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\devenv.com" "Required_path\solution.sln" /Project "Required_path\Setup\Setup.vdproj" /Build Release /Out
"Required_Path\vs_errors.txt"
I would be pretty surprised if you are able to build .vdproj files without installing Visual Studio.