Why is my key file's relative path changed from ..\ to *Undefined* when building with MSBuild? - msbuild

In my solution folder, there is a folder called Tools which is not included in the solution itself (because the "Show All Files" function of VS's Solution Explorer doesn't display it to include in the project). Inside is an SNK file for signing assemblies. Another programmer has signed a project with that file. When I pulled the project from Git, its "Signing" property showed the path as ..\..\..\Tools\key.snk.
Building the solution with VS is fine, but if I use MSBuild there will be an error that read:
CSC : error CS7027: Error signing output with public key from file
'*Undefined*Tools\key.snk' -- File not found.
[C:\Source\src\Client\Share\QED\QED.csproj]
I have tried re-signing the project myself with the file. The file path changed to key.snk, the SNK file was copied into the project, but the error stayed the same.
I'm using MSBuild 17 with VS2022.

Related

Visual Studio ASP.NET Web API Precompiled files placed in a different folder with TFS

I have an asp.net web api project whose output needs to be packaged in a setup project using wix.
I would like to precompile the site. The problem is that the precompilation process generates variable file names (ie. *.compiled files in particular).
I also would like to build the setup in a TFS build.
It seems that my only option is to generate a .wxs file wihtin the prebuild step of the wix project.
The .wxs files source paths are using $(var._My_Web_Project_.TargetDir). This seems to be translated to a Sources based directory.
I'm using paraffin to do that already and it works perfectly fine when building the solution with visual studio.
When building the solution through a TFS build, the .compiled files are copied to a Binaries folder, whereas all the other related web site files are copied to a Sources based directory.
The build errors are like the following :
The system cannot find the file 'd:\BuildAgents\___basedir___\Binaries\___web_project_dir\_PublishedWebSites\___site___\bin\textsample.cshtml.c6fb271c.compiled'.
The file is indeed in the Sources directory.
'd:\BuildAgents\___basedir___\Sources\___web_project_dir\_PublishedWebSites\___site___\bin\textsample.cshtml.c6fb271c.compiled'
I think I somehow need to redefine the aspnet_compiler output or something like this, but can't figure out how to do that.
The msbuild command line arguments are the follwing:
/p:GenerateProjectSpecificOutputFolder=true /p:VisualStudioVersion=14.0 /p:DeployOnBuild=true /p:PublishProfile=local /p:CleanWebProjectOutputDir=False /verbosity:d
EDIT 1: I'm using XAML build.
Any help appreciated.
EDIT 2:
With the new task based build, it works as is (no need to use an additional Copy Files task).
The aspnet_compiler output the .compiled files in the correct folder :
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p D:\BuildAgents\vNext\_work\1\s\Softs\__Solution__\__Web_Project\obj\Release\AspnetCompileMerge\Source -c D:\BuildAgents\vNext\_work\1\s\Softs\__Solution__\__Web_Project__\obj\Release\AspnetCompileMerge\TempBuildDir
In the new tasks based build system, it's easy to copy files from a source folder to a target folder with Copy Files task.
Source Folder: Folder that contains the files you want to copy.
Contents: Specify minimatch pattern filters (one on each line) that you want to apply to the list of files to be copied.
Target Folder: Folder where the files will be copied. In most cases you specify this folder using a variable.

Adding a folder with files to application - Visual Basic 2010

In my current project I have a folder with several files that the application needs to function properly. The folder is in the bin/debug folder and with the line Application.StartupPath I can easily access the files. It couldn't be easier.
However, when I publish the application the files don't seem to be included in the project, at least not at the StartupPath.
So my question is: how am I supposed to add this folder to my published application?
First, you'll need to include those files in your project. Then click each file in the Solution Explorer and in the Properties Windows change the value for "Copy to Output Directory" to "Copy Always".

Team City build error file not found

I'm having an issue with a Team City build. I added a web.config transform to my publish profile however the publish process can't seem to find the file.
The file Web.Stage.config does exist on the build server in C:\TeamCity\buildAgent\work\12d03f61c6f6df2f. Team City seems to not have added a backslash at the end of the directory path before appending the file name.
The error in full is listed below. Any help is appreciated.
Build errors
[15:08:47]website.publishproj.teamcity: Build target: MSDeployPublish (32s)
[15:09:03][website.publishproj.teamcity] CopyAllFilesToSingleFolderForMsdeploy (16s)
[15:09:04][CopyAllFilesToSingleFolderForMsdeploy] CopyPipelineFiles (15s)
[15:09:19][CopyPipelineFiles] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(2709, 5): Copying file C:\TeamCity\buildAgent\work\12d03f61c6f6df2fWeb.CRIStage.config to binobj\Debug\Package\PackageTmp\Web.CRIStage.config failed. Could not find file 'C:\TeamCity\buildAgent\work\12d03f61c6f6df2fWeb.Stage.config'.
[15:09:20][website.publishproj.teamcity] Project website.publishproj.teamcity failed.
As a work around you can give 'Artifacts Path' in your 'General Settings' tab of Build Configuration as \Web.Stage.config by adding a slash before the file name. So that it will take the file path properly as C:\TeamCity\buildAgent\work\12d03f61c6f6df2f\Web.Stage.config.

MSBuild - Nest an external file (file outside of the project folder) into a file in the project folder

I have the following scenario:
I have 2 projects:
Proj1
Proj2
Each of these projects needs access to a similar service (FooService) so I wrote up the Foo.svc and Foo.svc.cs files and put them in a directory that was outside of both of the project directories.
I then edited my Proj1.csproj file to do the following:
Foo.svc
This works fine in terms of editing and compiling the code, however I can't access the service: http://localhost/Proj1/Foo.svc << This does not exist (because the actual Foo.svc file is not in the Project directory).
So instead I copied the Foo.svc file inside each of the Projects and just left the code-behind file (Foo.svc.cs) in the common directory. However, now Visual Studio complains that "The parent file, 'Foo.svc', for file '..\Common\Foo.svc.cs' cannot be found in the project file. Probably because it is looking for the 'Foo.svc' file relative to the code-behind file?
Foo.svc
Is there any way to do what I'm looking for... keeping the code-behind outside of both project directories (so they can both link to it) and somehow have svc files that are accessible in my IIS on localhost and have it so that the code-behind file folds into the svc file in Visual Studio?
What you're talking about is altering your MSBuild file (also known as a csproj file - http://msdn.microsoft.com/en-us/library/bb629388.aspx)
I tried to simulate what you're doing and I don't think there is a solution that would fit what you want. You're right, your project will work just fine, but aesthetically you can't have a file external to the project directory nested to a file inside of the project directory.

How do I access an XML file that is included in the project?

I have added an XML file (File.xml) into a project (I can see it in the Solution Explorer), it resides at the root directory level of the project i.e. the same level as the VB program (.vb), the bin directory and the References directory etc..
I try accessing it using XmlDocument.Load("File.xml") ... but it doesn't find it. I get
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Xml.dll
Any idea where the file is or how I 'address' it?
Thanks for any help
Oliver
Is the file copied to the output directory? Click on the file, look at the properties in the VS editor, and set the "Build Action" to Content and "Copy to Output Directory" to either "Copy always" or "Copy if newer" (depending on what you need).
In the Publish property go to
Application Files --> Look for the XML file: If the publish status = Data File, then the File will be copied to the Application DATA folder.
If you want the xml to be inside the programs directory change the publish status to: Include. This will do the trick.
Try this:
XmlDocument.LoadXml(System.IO.Path.GetFullPath(Application.StartupPath & "\File.xml"))
It's worth a shot I guess. My question: is it possible to edit a file that's placed in the project?